AbstractDoctrineMiddlewareFactory::__callStatic()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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