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
Pull Request — master (#3)
by Cees-Jan
02:31
created

Factory::gatherMapping()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 20
cp 0
rs 8.9713
cc 3
eloc 13
nc 3
nop 0
crap 12
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\CommandBus;
4
5
use Composed\Package;
6
use function Composed\packages;
7
use function igorw\get_in;
8
use Interop\Container\ContainerInterface;
9
use League\Tactician\Container\ContainerLocator;
10
use League\Tactician\Handler\CommandHandlerMiddleware;
11
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor;
12
use League\Tactician\Handler\MethodNameInflector\HandleInflector;
13
use React\EventLoop\LoopInterface;
14
use WyriHaximus\Tactician\CommandHandler\Mapper;
15
16
final class Factory
17
{
18
    public static function create(ContainerInterface $container)
19
    {
20
        $commandToHandlerMap = self::gatherMapping();
21
22
        $containerLocator = new ContainerLocator(
23
            $container,
24
            $commandToHandlerMap
25
        );
26
27
        $commandHandlerMiddleware = new CommandHandlerMiddleware(
28
            new ClassNameExtractor(),
29
            $containerLocator,
30
            new HandleInflector()
31
        );
32
33
        return new CommandBus(
34
            $container->get(LoopInterface::class),
35
            $commandHandlerMiddleware
36
        );
37
    }
38
39
    private static function gatherMapping()
40
    {
41
        $map = [];
42
        /** @var Package $package */
43
        foreach (packages() as $package) {
44
            $config = $package->getConfig('extra');
45
            $mapping = get_in(
46
                $config,
47
                [
48
                    'api-clients',
49
                    'command-bus'
50
                ],
51
                false
52
            );
53
54
            if ($mapping === false) {
55
                continue;
56
            }
57
58
            $map += Mapper::map($package->getPath($mapping['path']), $mapping['namespace']);
59
        }
60
61
        return $map;
62
    }
63
}
64