|
12 | 12 |
|
13 | 13 | final class NodeCodeSampleProvider |
14 | 14 | { |
| 15 | + private Standard $standardPrinter; |
| 16 | + |
15 | 17 | public function __construct( |
16 | | - private readonly Standard $standard, |
17 | | - private readonly PhpFilesFinder $phpFilesFinder, |
18 | 18 | ) { |
| 19 | + $this->standardPrinter = new Standard(); |
19 | 20 | } |
20 | 21 |
|
21 | 22 | /** |
22 | 23 | * @return array<class-string<Node>, array<int, NodeCodeSample>> |
23 | 24 | */ |
24 | 25 | public function provide(): array |
25 | 26 | { |
26 | | - $phpFilePaths = $this->phpFilesFinder->findPhpFiles([__DIR__ . '/../snippet']); |
| 27 | + $phpFileInfos = PhpFilesFinder::find([__DIR__ . '/../snippet']); |
27 | 28 |
|
28 | 29 | $nodeCodeSamplesByNodeClass = []; |
29 | 30 |
|
30 | | - foreach ($phpFilePaths as $phpFilePath) { |
| 31 | + foreach ($phpFileInfos as $phpFileInfo) { |
31 | 32 | /** @var Node $node */ |
32 | | - $node = include $phpFilePath; |
33 | | - |
34 | | - /** @var string $fileContents */ |
35 | | - $fileContents = file_get_contents($phpFilePath); |
| 33 | + $node = include $phpFileInfo->getRealPath(); |
36 | 34 |
|
37 | | - $errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFilePath, Node::class); |
| 35 | + $errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFileInfo, Node::class); |
38 | 36 | Assert::isInstanceOf($node, Node::class, $errorMessage); |
39 | 37 |
|
| 38 | + /** @var string $fileContents */ |
| 39 | + $fileContents = $phpFileInfo->getContents(); |
| 40 | + |
40 | 41 | $nodeClass = $node::class; |
41 | 42 |
|
42 | | - $printedContent = $this->standard->prettyPrint([$node]); |
| 43 | + $printedContent = $this->standardPrinter->prettyPrint([$node]); |
43 | 44 |
|
44 | 45 | $nodeCodeSamplesByNodeClass[$nodeClass][] = new NodeCodeSample($fileContents, $printedContent); |
45 | 46 | } |
|
0 commit comments