StopWorkersCommandFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Messenger\Factory\Command;
6
7
use Psr\Cache\CacheItemPoolInterface;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Messenger\Command\StopWorkersCommand;
10
use TMV\Messenger\Exception\InvalidArgumentException;
11
12
final class StopWorkersCommandFactory
13
{
14 2
    public function __invoke(ContainerInterface $container): StopWorkersCommand
15
    {
16 2
        $config = $container->has('config') ? $container->get('config') : [];
17
        /** @var string|null $cachePoolForRestartSignal */
18 2
        $cachePoolForRestartSignal = $config['messenger']['cache_pool_for_restart_signal'] ?? null;
19
20 2
        if (null === $cachePoolForRestartSignal) {
21 1
            throw new InvalidArgumentException('Invalid cache_pool_for_restart_signal name');
22
        }
23
24
        /** @var CacheItemPoolInterface $cachePoolForRestartSignal */
25 1
        $cachePoolForRestartSignal = $container->get($cachePoolForRestartSignal);
0 ignored issues
show
Bug introduced by
$cachePoolForRestartSignal of type Psr\Cache\CacheItemPoolInterface is incompatible with the type string expected by parameter $id of Psr\Container\ContainerInterface::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $cachePoolForRestartSignal = $container->get(/** @scrutinizer ignore-type */ $cachePoolForRestartSignal);
Loading history...
26
27 1
        return new StopWorkersCommand($cachePoolForRestartSignal);
28
    }
29
}
30