Conditions | 6 |
Paths | 15 |
Total Lines | 35 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
9 | public static function getReflectionClassesFromDirectories(string $path): \Iterator |
||
10 | { |
||
11 | $iterator = new \RegexIterator( |
||
12 | new \RecursiveIteratorIterator( |
||
13 | new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), |
||
14 | \RecursiveIteratorIterator::LEAVES_ONLY |
||
15 | ), |
||
16 | '/^.+\.php$/i', |
||
17 | \RegexIterator::GET_MATCH |
||
18 | ); |
||
19 | |||
20 | foreach ($iterator as $file) { |
||
21 | $sourceFile = $file[0]; |
||
22 | |||
23 | if (!preg_match('(^phar:)i', $sourceFile)) { |
||
24 | $sourceFile = realpath($sourceFile); |
||
25 | } |
||
26 | |||
27 | try { |
||
28 | require_once $sourceFile; |
||
29 | } catch (\Throwable $t) { |
||
30 | // invalid PHP file (example: missing parent class) |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | $includedFiles[$sourceFile] = true; |
||
35 | } |
||
36 | $declared = array_merge(get_declared_classes(), get_declared_interfaces()); |
||
37 | |||
38 | foreach ($declared as $className) { |
||
39 | $reflectionClass = new \ReflectionClass($className); |
||
40 | $sourceFile = $reflectionClass->getFileName(); |
||
41 | |||
42 | if (isset($includedFiles[$sourceFile])) { |
||
43 | yield $className => $reflectionClass; |
||
44 | } |
||
48 |