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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 48
ccs 0
cts 37
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 1
B gatherMapping() 0 24 3
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