Passed
Push — master ( 109e7c...79a79c )
by Thomas Mauro
02:15
created

__callStatic()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Factory\Middleware;
6
7
use Doctrine\Persistence\ManagerRegistry;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
10
use TMV\Laminas\Messenger\Exception\InvalidArgumentException;
11
use TMV\Laminas\Messenger\Middleware\DoctrineTransactionMiddleware;
12
13
/**
14 1
 * @psalm-api
15
 */
16 1
final class DoctrineTransactionMiddlewareFactory extends AbstractDoctrineMiddlewareFactory
17 1
{
18 1
    public function __invoke(ContainerInterface $container): MiddlewareInterface
19
    {
20
        /** @var ManagerRegistry $manager */
21
        $manager = $container->get(ManagerRegistry::class);
22
23
        return new DoctrineTransactionMiddleware(
24
            $manager,
25
            $this->connectionName ?? $manager->getDefaultConnectionName(),
26
        );
27
    }
28
29
    /**
30
     * @psalm-api
31
     *
32
     * @param array<int, mixed> $arguments
33
     */
34
    public static function __callStatic(string $name, array $arguments): MiddlewareInterface
35
    {
36
        if (! array_key_exists(0, $arguments) || ! $arguments[0] instanceof ContainerInterface) {
37
            throw new InvalidArgumentException(sprintf(
38
                'The first argument must be of type %s',
39
                ContainerInterface::class
40
            ));
41
        }
42
43
        return (new self($name))($arguments[0]);
44
    }
45
}
46