QueueConsumerFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 10
cc 2
nc 2
nop 2
crap 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 $extension) {
24 1
            $extensions[] = $container->get($extension);
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