Passed
Push — master ( 9ab24f...a560c8 )
by Koldo
02:45
created

ActionContainerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Queue\Container;
6
7
use Antidot\Queue\ActionContainer;
8
use Antidot\Queue\Container\Config\ConfigProvider;
9
use Assert\AssertionFailedException;
10
use Psr\Container\ContainerInterface;
11
12
class ActionContainerFactory
13
{
14
    /**
15
     * @param ContainerInterface $container
16
     * @param string $contextName
17
     * @return ActionContainer
18
     * @throws AssertionFailedException
19
     */
20 2
    public function __invoke(
21
        ContainerInterface $container,
22
        string $contextName = ConfigProvider::DEFAULT_CONTEXT
23
    ): ActionContainer {
24 2
        $contextConfig = ConfigProvider::getContextConfig($contextName, $container->get(ConfigProvider::CONFIG_KEY));
25 1
        foreach ($contextConfig[ConfigProvider::MESSAGE_TYPES_KEY] ?? [] as $messageType => $action) {
26 1
            $actions[$messageType] = static fn() => $container->get($action);
27
        }
28
29 1
        return new ActionContainer($actions ?? []);
30
    }
31
}
32