RedisCompilerPass::process()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 16
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 28
ccs 17
cts 17
cp 1
crap 9
rs 8.0555
1
<?php
2
3
namespace Dtc\QueueBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...r\CompilerPassInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\DependencyInjection\Definition;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\DependencyInjection\Definition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\DependencyInjection\Reference;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\DependencyInjection\Reference was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class RedisCompilerPass implements CompilerPassInterface
11
{
12 4
    public function process(ContainerBuilder $container): void
13
    {
14 4
        if ($container->hasParameter('dtc_queue.redis.snc_redis.type') &&
15 4
            $container->getParameter('dtc_queue.redis.snc_redis.type')) {
16 1
            $this->processSncRedis($container);
17
18 1
            return;
19
        }
20
21 3
        if ($container->hasParameter('dtc_queue.redis.predis.dsn') &&
22 3
            $container->getParameter('dtc_queue.redis.predis.dsn')) {
23 1
            $this->processPredisDsn($container);
24
25 1
            return;
26
        }
27
28 3
        if ($container->hasParameter('dtc_queue.redis.predis.connection_parameters') &&
29 3
            $container->getParameter('dtc_queue.redis.predis.connection_parameters')) {
30 1
            $this->processPredisConnectionParameters($container);
31
32 1
            return;
33
        }
34
35 2
        if ($container->hasParameter('dtc_queue.redis.phpredis.host') &&
36 2
            $container->getParameter('dtc_queue.redis.phpredis.host')) {
37 1
            $this->processPhpRedis($container);
38
39 1
            return;
40
        }
41 1
    }
42
43 1
    protected function processSncRedis(ContainerBuilder $container)
44
    {
45 1
        $type = $container->getParameter('dtc_queue.redis.snc_redis.type');
46 1
        $alias = $container->getParameter('dtc_queue.redis.snc_redis.alias');
47 1
        $class = 'PhpRedis';
48 1
        if ('predis' == $type) {
49 1
            $class = 'Predis';
50
        }
51
52 1
        $this->setRedis($container, $class, 'snc_redis.'.$alias, $type);
53 1
    }
54
55 3
    protected function setRedis(ContainerBuilder $container, $class, $reference, $type)
56
    {
57 3
        $definition = new Definition(
58 3
            'Dtc\\QueueBundle\\Redis\\'.$class,
59 3
            [new Reference($reference)]
60
        );
61 3
        $container->setDefinition('dtc_queue.'.$type, $definition);
62
63 3
        $definition = $container->getDefinition('dtc_queue.manager.job.redis');
64 3
        $definition->addMethodCall('setRedis', [new Reference('dtc_queue.'.$type)]);
65 3
    }
66
67 1
    protected function processPredisDsn(ContainerBuilder $container)
68
    {
69 1
        $definition = new Definition(
70 1
            'Predis\\Client',
71 1
            [$container->getParameter('dtc_queue.redis.predis.dsn')]
72
        );
73 1
        $container->setDefinition('dtc_queue.predis.client', $definition);
74
75 1
        $this->setRedis($container, 'Predis', 'dtc_queue.predis.client', 'predis');
76 1
    }
77
78 1
    protected function processPhpRedis(ContainerBuilder $container)
79
    {
80 1
        $definition = new Definition(
81 1
            'Redis'
82
        );
83
84 1
        $arguments = [$container->getParameter('dtc_queue.redis.phpredis.host'),
85 1
            $container->getParameter('dtc_queue.redis.phpredis.port'),
86 1
            $container->getParameter('dtc_queue.redis.phpredis.timeout'),
87
            null,
88 1
            $container->getParameter('dtc_queue.redis.phpredis.retry_interval'),
89 1
            $container->getParameter('dtc_queue.redis.phpredis.read_timeout'), ];
90 1
        $definition->addMethodCall('connect', $arguments);
91 1
        if ($container->hasParameter('dtc_queue.redis.phpredis.auth') && null !== ($auth = $container->getParameter('dtc_queue.redis.phpredis.auth'))) {
92
            $definition->addMethodCall('auth', [$auth]);
93
        }
94 1
        $container->setDefinition('dtc_queue.phpredis.connection', $definition);
95
96 1
        $this->setRedis($container, 'PhpRedis', 'dtc_queue.phpredis.connection', 'phpredis');
97 1
    }
98
99 1
    protected function processPredisConnectionParameters(ContainerBuilder $container)
100
    {
101 1
        $definition = new Definition(
102 1
            'Predis\\Client',
103 1
            [$container->getParameter('dtc_queue.redis.predis.connection_parameters')]
104
        );
105 1
        $container->setDefinition('dtc_queue.predis.client', $definition);
106
107 1
        $this->setRedis($container, 'Predis', 'dtc_queue.predis.client', 'predis');
108 1
    }
109
}
110