Skip to content

Commit 1c5fce7

Browse files
committed
Add support for code style in FileGenerator - Close #67
1 parent 5c294f1 commit 1c5fce7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/FileCodeGenerator.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)