GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d46d29...eb6a59 )
by Cees-Jan
03:22 queued 01:01
created

Mapper::map()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 34
rs 8.439
cc 5
eloc 19
nc 5
nop 2
1
<?php
2
3
namespace WyriHaximus\Tactician\CommandHandler;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use RecursiveDirectoryIterator;
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
42
            $mapping[$class] = $annotation->getHandler();
43
        }
44
45
        return $mapping;
46
    }
47
48
    public static function mapInstanciated($path, $namespace)
49
    {
50
        $mapping = [];
51
52
        foreach (self::map($path, $namespace) as $command => $handler) {
53
            $mapping[$command] = new $handler();
54
        }
55
56
        return $mapping;
57
    }
58
}
59