AbstractDoctrineMiddlewareFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 10 3
A __construct() 0 3 1
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