TransportProviderFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
dl 0
loc 20
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Factory\Transport;
6
7
use Laminas\ServiceManager\ServiceManager;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Messenger\Transport\TransportInterface;
10
use Symfony\Contracts\Service\ServiceProviderInterface;
11
use TMV\Laminas\Messenger\ServiceProvider;
12
13
class TransportProviderFactory
14
{
15
    public function __invoke(ContainerInterface $container): ServiceProviderInterface
16
    {
17
        $factories = [];
18
19
        /** @var array{messenger: array{transports?: array<string, mixed>}} $config */
20
        $config = $container->has('config') ? $container->get('config') : [];
21
        $transportNames = array_keys($config['messenger']['transports'] ?? []);
22
23
        foreach ($transportNames as $name) {
24
            $factories[(string) $name] = static function () use ($name, $container): TransportInterface {
25
                /** @var TransportInterface $transport */
26
                $transport = $container->get((string) $name);
27
28
                return $transport;
29
            };
30
        }
31
32
        return new ServiceProvider(new ServiceManager(['factories' => $factories]), $factories);
0 ignored issues
show
Unused Code introduced by
The call to TMV\Laminas\Messenger\Se...Provider::__construct() has too many arguments starting with $factories. ( Ignorable by Annotation )

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

32
        return /** @scrutinizer ignore-call */ new ServiceProvider(new ServiceManager(['factories' => $factories]), $factories);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
new Laminas\ServiceManag...tories' => $factories)) of type Laminas\ServiceManager\ServiceManager is incompatible with the type array expected by parameter $factories of TMV\Laminas\Messenger\Se...Provider::__construct(). ( Ignorable by Annotation )

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

32
        return new ServiceProvider(/** @scrutinizer ignore-type */ new ServiceManager(['factories' => $factories]), $factories);
Loading history...
33
    }
34
}
35