RedisCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 34
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 2
A getArguments() 0 4 1
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
9
10
/**
11
 * @CompilerPass(priority=9)
12
 */
13
class RedisCompilerPass implements CompilerPassInterface
14
{
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 2
    public function process(ContainerBuilder $container)
20
    {
21 2
        $redis = $container->findDefinition('Redis');
22
23 2
        $masterArguments = $this->getArguments($container, '');
24
25
        try {
26 2
            $slaveArguments = $this->getArguments($container, '.slave');
27
            $parameters = [$masterArguments, $slaveArguments];
28
            $options    = ['replication' => true];
29
30
            $redis->setArguments([$parameters, $options]);
31 2
        } catch (ParameterNotFoundException $e) {
32
            // master only
33 2
            $redis->setArguments([$masterArguments]);
34
        }
35 2
    }
36
37
    /**
38
     * @param ContainerBuilder $container
39
     * @param string $prefix
40
     * @return string
41
     */
42 2
    protected function getArguments(ContainerBuilder $container, string $prefix) : string
43
    {
44 2
        return $container->getParameter("redis$prefix.connection");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $prefix instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
45
    }
46
}
47