Conditions | 5 |
Paths | 5 |
Total Lines | 34 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | use RecursiveIteratorIterator; |
||
8 | use ReflectionClass; |
||
9 | use WyriHaximus\Tactician\CommandHandler\Annotations\Handler; |
||
10 | |||
11 | final class Mapper |
||
12 | { |
||
13 | public static function map($path, $namespace) |
||
14 | { |
||
15 | $reader = new AnnotationReader(); |
||
16 | $mapping = []; |
||
17 | |||
18 | $directory = new RecursiveDirectoryIterator($path); |
||
19 | $directory = new RecursiveIteratorIterator($directory); |
||
20 | |||
21 | foreach ($directory as $node) { |
||
22 | if (!is_file($node->getPathname())) { |
||
23 | continue; |
||
24 | } |
||
25 | |||
26 | $file = substr($node->getPathname(), strlen($path)); |
||
27 | $file = ltrim($file, DIRECTORY_SEPARATOR); |
||
28 | $file = rtrim($file, '.php'); |
||
29 | |||
30 | $class = $namespace . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $file); |
||
31 | |||
32 | if (!class_exists($class)) { |
||
33 | continue; |
||
34 | } |
||
35 | |||
36 | $annotation = $reader->getClassAnnotation(new ReflectionClass($class), Handler::class); |
||
37 | |||
38 | if (!($annotation instanceof Handler)) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
59 |