Passed
Push — master ( 8346df...04aa1f )
by Koldo
02:40
created

QueueConsumerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 9
c 1
b 0
f 1
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Queue\Container;
6
7
use Antidot\Queue\Container\Config\ConfigProvider;
8
use Enqueue\Consumption\ChainExtension;
9
use Enqueue\Consumption\QueueConsumer;
10
use Enqueue\Consumption\QueueConsumerInterface;
11
use Psr\Container\ContainerInterface;
12
use Psr\Log\LoggerInterface;
13
14
class QueueConsumerFactory
15
{
16 1
    public function __invoke(
17
        ContainerInterface $container,
18
        string $contextName = ConfigProvider::DEFAULT_CONTEXT
19
    ): QueueConsumerInterface {
20 1
        $contextConfig = ConfigProvider::getContextConfig($contextName, $container->get(ConfigProvider::CONFIG_KEY));
21
22 1
        $extensions = [];
23 1
        foreach ($contextConfig['extensions'] ?? [] as $extensionName) {
24 1
            $extensions[] = $container->get($extensionName);
25
        }
26
27 1
        return new QueueConsumer(
28 1
            $container->get($contextConfig[ConfigProvider::CONTEXT_SERVICE_KEY]),
29 1
            new ChainExtension($extensions),
30 1
            [],
31 1
            $container->get(LoggerInterface::class)
32
        );
33
    }
34
}
35