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 ( cde496...0672dd )
by Cees-Jan
01:41
created

Mapper::map()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 4
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\Tactician\CommandHandler;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\Reader;
7
use ReflectionClass;
8
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
9
use function WyriHaximus\listClassesInDirectory;
10
11
final class Mapper
12
{
13 1
    public static function mapInstantiated(string $path, ?Reader $reader = null): iterable
14
    {
15 1
        foreach (self::map($path, $reader) as $command => $handler) {
16 1
            yield $command => new $handler();
17
        }
18 1
    }
19
20 2
    public static function map(string $path, ?Reader $reader = null): iterable
21
    {
22 2
        foreach (listClassesInDirectory($path) as $class) {
23 2
            $handler = self::getHandlerByCommand($class, $reader);
24
25 2
            if ($handler === null || !class_exists($handler)) {
26 2
                continue;
27
            }
28
29 2
            yield $class => $handler;
30
        }
31 2
    }
32
33 4
    public static function getHandlerByCommand(string $command, ?Reader $reader = null): ?string
34
    {
35 4
        $annotation = ($reader ?? new AnnotationReader())->getClassAnnotation(new ReflectionClass($command), Handler::class);
36
37 4
        if (!($annotation instanceof Handler)) {
38 3
            return null;
39
        }
40
41 3
        return $annotation->getHandler();
42
    }
43
}
44