FailedMessagesRemoveCommandFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Factory\Command;
6
7
use Psr\Container\ContainerInterface;
8
use Symfony\Component\Messenger\Command\FailedMessagesRemoveCommand;
9
use Symfony\Contracts\Service\ServiceProviderInterface;
10
use TMV\Laminas\Messenger\Exception\InvalidArgumentException;
11
use TMV\Laminas\Messenger\ServiceProvider;
12
13 2
/**
14
 * @psalm-api
15 2
 */
16 2
final class FailedMessagesRemoveCommandFactory
17
{
18 2
    public function __invoke(ContainerInterface $container): FailedMessagesRemoveCommand
19 1
    {
20
        /** @var array{messenger: array{failure_transport?: string}} $config */
21
        $config = $container->has('config') ? $container->get('config') : [];
22
        $failureTransportName = $config['messenger']['failure_transport'] ?? null;
23 1
24
        if (null === $failureTransportName) {
25 1
            throw new InvalidArgumentException('Invalid failure_transport name');
26 1
        }
27 1
28
        /** @var ServiceProviderInterface $receiverLocator */
29
        $receiverLocator = $container->get('messenger.receivers_locator');
30
31
        return new FailedMessagesRemoveCommand(
32
            $failureTransportName,
33
            new ServiceProvider([
34
                $failureTransportName => static function () use ($receiverLocator, $failureTransportName) { return $receiverLocator->get($failureTransportName); },
35
            ]),
36
        );
37
    }
38
}
39