AddBusNameStampMiddlewareFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 34
rs 10
ccs 11
cts 11
cp 1
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set_state() 0 3 1
A __construct() 0 3 1
A __callStatic() 0 10 3
A __invoke() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Factory\Middleware;
6
7
use Psr\Container\ContainerInterface;
8
use Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware;
9
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
10
use TMV\Laminas\Messenger\Exception\InvalidArgumentException;
11
12
use function array_key_exists;
13
use function sprintf;
14
15
/**
16
 * @psalm-api
17
 */
18 1
final class AddBusNameStampMiddlewareFactory
19
{
20 1
    private string $busName;
21 1
22
    public function __construct(string $busName = 'messenger.bus.default')
23 1
    {
24
        $this->busName = $busName;
25 1
    }
26
27
    public function __invoke(ContainerInterface $container): AddBusNameStampMiddleware
28
    {
29
        return new AddBusNameStampMiddleware($this->busName);
30
    }
31
32
    public static function __set_state(array $data): self
33
    {
34 2
        return new self($data['busName'] ?? null);
0 ignored issues
show
Bug introduced by
It seems like $data['busName'] ?? null can also be of type null; however, parameter $busName of TMV\Laminas\Messenger\Fa...eFactory::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return new self(/** @scrutinizer ignore-type */ $data['busName'] ?? null);
Loading history...
35
    }
36 2
37 1
    /**
38 1
     * @psalm-api
39 1
     *
40
     * @param array<int, mixed> $arguments
41
     */
42
    public static function __callStatic(string $name, array $arguments): MiddlewareInterface
43 1
    {
44
        if (! array_key_exists(0, $arguments) || ! $arguments[0] instanceof ContainerInterface) {
45
            throw new InvalidArgumentException(sprintf(
46
                'The first argument must be of type %s',
47
                ContainerInterface::class
48
            ));
49
        }
50
51
        return (new self($name))($arguments[0]);
52
    }
53
}
54