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 ( 53fb33...90de41 )
by Cees-Jan
24s
created

Factory::resolveMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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