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 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlerByCommand() 0 10 2
A mapInstantiated() 0 6 2
A map() 0 12 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 function WyriHaximus\listClassesInDirectory;
9
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
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