@@ -43,11 +43,13 @@ public function __construct(
43
43
*
44
44
* @param FileCollection $fileCollection
45
45
* @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
46
47
* @return array<string, string> List of filename => code
47
48
*/
48
49
public function generateFiles (
49
50
FileCollection $ fileCollection ,
50
- callable $ currentFileAst = null
51
+ callable $ currentFileAst = null ,
52
+ callable $ applyCodeStyle = null
51
53
): array {
52
54
$ files = [];
53
55
@@ -62,6 +64,10 @@ public function generateFiles(
62
64
};
63
65
}
64
66
67
+ if ($ applyCodeStyle === null ) {
68
+ $ applyCodeStyle = static fn (string $ code ) => $ code ;
69
+ }
70
+
65
71
$ previousNamespace = '__invalid//namespace__ ' ;
66
72
67
73
foreach ($ fileCollection as $ classBuilder ) {
@@ -75,9 +81,9 @@ public function generateFiles(
75
81
$ nodeTraverser = new NodeTraverser ();
76
82
$ classBuilder ->injectVisitors ($ nodeTraverser , $ this ->parser );
77
83
78
- $ files [$ filename ] = $ this ->printer ->prettyPrintFile (
84
+ $ files [$ filename ] = ( $ applyCodeStyle )( $ this ->printer ->prettyPrintFile (
79
85
$ nodeTraverser ->traverse ($ currentFileAst ($ classBuilder , $ classInfo ))
80
- );
86
+ )) ;
81
87
}
82
88
83
89
return $ files ;
0 commit comments