@@ -43,11 +43,13 @@ public function __construct(
4343 *
4444 * @param FileCollection $fileCollection
4545 * @param callable|null $currentFileAst Callable to return current file AST, if null, file will be overwritten
46+ * @param callable|null $applyCodeStyle Apply additional code style
4647 * @return array<string, string> List of filename => code
4748 */
4849 public function generateFiles (
4950 FileCollection $ fileCollection ,
50- callable $ currentFileAst = null
51+ callable $ currentFileAst = null ,
52+ callable $ applyCodeStyle = null
5153 ): array {
5254 $ files = [];
5355
@@ -62,6 +64,10 @@ public function generateFiles(
6264 };
6365 }
6466
67+ if ($ applyCodeStyle === null ) {
68+ $ applyCodeStyle = static fn (string $ code ) => $ code ;
69+ }
70+
6571 $ previousNamespace = '__invalid//namespace__ ' ;
6672
6773 foreach ($ fileCollection as $ classBuilder ) {
@@ -75,9 +81,9 @@ public function generateFiles(
7581 $ nodeTraverser = new NodeTraverser ();
7682 $ classBuilder ->injectVisitors ($ nodeTraverser , $ this ->parser );
7783
78- $ files [$ filename ] = $ this ->printer ->prettyPrintFile (
84+ $ files [$ filename ] = ( $ applyCodeStyle )( $ this ->printer ->prettyPrintFile (
7985 $ nodeTraverser ->traverse ($ currentFileAst ($ classBuilder , $ classInfo ))
80- );
86+ )) ;
8187 }
8288
8389 return $ files ;
0 commit comments