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.

Mapper   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 78
ccs 21
cts 22
cp 0.9545
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A map() 0 16 4
A getJobsFromCommand() 0 10 2
A hasCommand() 0 4 1
A getCommand() 0 8 2
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 function WyriHaximus\listClassesInDirectory;
10
use WyriHaximus\Tactician\JobCommand\Annotations\Job;
11
12
final class Mapper implements MapperInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    private $map = [];
18
19
    /** @var Reader */
20
    private $reader;
21
22
    /**
23
     * @param Reader|null $reader
24
     */
25 6
    public function __construct(?Reader $reader = null)
26
    {
27 6
        $this->reader = $reader ?? new AnnotationReader();
28 6
    }
29
30
    /**
31
     * @param  string $path
32
     * @return Mapper
33
     */
34 2
    public function map(string $path): Mapper
35
    {
36 2
        foreach (listClassesInDirectory($path) as $class) {
37 2
            $jobs = self::getJobsFromCommand($class);
38
39 2
            if (\count($jobs) === 0) {
40
                continue;
41
            }
42
43 2
            foreach ($jobs as $job) {
44 2
                $this->map[$job] = $class;
45
            }
46
        }
47
48 2
        return $this;
49
    }
50
51
    /**
52
     * @param  string $command
53
     * @param  Reader $reader
0 ignored issues
show
Bug introduced by
There is no parameter named $reader. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     * @return array
55
     */
56 5
    public function getJobsFromCommand(string $command): array
57
    {
58 5
        $annotation = $this->reader->getClassAnnotation(new ReflectionClass($command), Job::class);
59
60 5
        if (!($annotation instanceof Job)) {
61 1
            return [];
62
        }
63
64 4
        return $annotation->getJobs();
65
    }
66
67
    /**
68
     * @param  string $job
69
     * @return bool
70
     */
71 2
    public function hasCommand(string $job): bool
72
    {
73 2
        return isset($this->map[$job]);
74
    }
75
76
    /**
77
     * @param  string    $job
78
     * @throws Exception
79
     * @return string
80
     */
81 3
    public function getCommand(string $job): string
82
    {
83 3
        if (isset($this->map[$job])) {
84 2
            return $this->map[$job];
85
        }
86
87 1
        throw new Exception('No command known for job: ' . $job);
88
    }
89
}
90