FailedMessagesShowCommandFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 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