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 ( 047d03...b8d187 )
by Cees-Jan
24s
created

Mapper::map()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.6666
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\Tactician\JobCommand;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\Reader;
7
use Exception;
8
use ReflectionClass;
9
use WyriHaximus\Tactician\JobCommand\Annotations\Job;
10
use function WyriHaximus\listClassesInDirectory;
11
12
final class Mapper implements MapperInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    private $map = [];
18
19
    /**
20
     * @param  string $path
21
     * @return Mapper
22
     */
23
    public function map(string $path): Mapper
24
    {
25 1
        $reader = new AnnotationReader();
26
27 1
        foreach (listClassesInDirectory($path) as $class) {
28
            $jobs = self::getJobsFromCommand($class, $reader);
29 1
30 1
            if (count($jobs) === 0) {
31
                continue;
32 1
            }
33 1
34 1
            foreach ($jobs as $job) {
35
                $this->map[$job] = $class;
36
            }
37 1
        }
38 1
39 1
        return $this;
40
    }
41 1
42
    /**
43 1
     * @param  string $command
44
     * @param  Reader $reader
45
     * @return array
46
     */
47 1
    public function getJobsFromCommand(string $command, Reader $reader): array
48
    {
49 1
        $annotation = $reader->getClassAnnotation(new ReflectionClass($command), Job::class);
50
51
        if (!($annotation instanceof Job)) {
52
            return [];
53 1
        }
54 1
55
        return $annotation->getJobs();
56
    }
57
58 1
    /**
59
     * @param  string $job
60
     * @return bool
61
     */
62
    public function hasCommand(string $job): bool
63
    {
64
        return isset($this->map[$job]);
65
    }
66 4
67
    /**
68 4
     * @param  string    $job
69
     * @throws Exception
70 4
     * @return string
71 1
     */
72
    public function getCommand(string $job): string
73
    {
74 3
        if (isset($this->map[$job])) {
75
            return $this->map[$job];
76
        }
77
78
        throw new Exception('No command known for job: ' . $job);
79
    }
80
}
81