AddBusNameStampMiddlewareFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\AddBusNameStampMiddleware;
11
use TMV\Messenger\Exception\InvalidArgumentException;
12
13
final class AddBusNameStampMiddlewareFactory
14
{
15
    /** @var string */
16
    private $busName;
17
18 1
    public function __construct(string $busName = 'messenger.bus.default')
19
    {
20 1
        $this->busName = $busName;
21 1
    }
22
23 1
    public function __invoke(ContainerInterface $container): AddBusNameStampMiddleware
24
    {
25 1
        return new AddBusNameStampMiddleware($this->busName);
26
    }
27
28
    /**
29
     * @param string $name
30
     * @param array $arguments
31
     *
32
     * @return AddBusNameStampMiddleware
33
     */
34 2
    public static function __callStatic(string $name, array $arguments): AddBusNameStampMiddleware
35
    {
36 2
        if (! array_key_exists(0, $arguments) || ! $arguments[0] instanceof ContainerInterface) {
37 1
            throw new InvalidArgumentException(sprintf(
38 1
                'The first argument must be of type %s',
39 1
                ContainerInterface::class
40
            ));
41
        }
42
43 1
        return (new static($name))($arguments[0]);
44
    }
45
}
46