DoctrineTransportFactoryFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 14
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Bridge\Doctrine\Factory\Transport;
6
7
use Doctrine\Persistence\ConnectionRegistry;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
10
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
11
use TMV\Laminas\Messenger\ConfigProvider;
12
use TMV\Laminas\Messenger\Factory\Transport\UnsupportedTransportFactory;
13
14
/**
15
 * @psalm-api
16
 */
17
final class DoctrineTransportFactoryFactory
18
{
19
    public function __invoke(ContainerInterface $container): TransportFactoryInterface
20
    {
21
        if (! class_exists(DoctrineTransportFactory::class)) {
22
            return new UnsupportedTransportFactory();
23
        }
24
25
        /** @var array{connection_registry?: string|null, manager_registry: string} $config */
26
        $config = $container->get('config')[ConfigProvider::CONFIG_KEY]['doctrine'] ?? [];
27
        /** @var ConnectionRegistry $connectionRegistry */
28
        $connectionRegistry = $container->get($config['connection_registry'] ?? $config['manager_registry']);
29
30
        return new DoctrineTransportFactory($connectionRegistry);
31
    }
32
}
33