FailedMessagesShowCommandFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 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\FailedMessagesShowCommand;
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 FailedMessagesShowCommandFactory
17
{
18 2
    public function __invoke(ContainerInterface $container): FailedMessagesShowCommand
19 1
    {
20
        $config = $container->has('config') ? $container->get('config') : [];
21
        $failureTransportName = $config['messenger']['failure_transport'] ?? null;
22
23 1
        if (null === $failureTransportName) {
24
            throw new InvalidArgumentException('Invalid failure_transport name');
25 1
        }
26 1
27 1
        /** @var ServiceProviderInterface $receiverLocator */
28
        $receiverLocator = $container->get('messenger.receivers_locator');
29
30
        return new FailedMessagesShowCommand(
31
            $failureTransportName,
32
            new ServiceProvider([
33
                $failureTransportName => static function () use ($receiverLocator, $failureTransportName) { return $receiverLocator->get($failureTransportName); },
34
            ]),
35
        );
36
    }
37
}
38