Completed
Push — master ( c458f8...eeebc2 )
by Matze
06:56
created

RedisCompilerPass::process()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.5

Importance

Changes 11
Bugs 0 Features 6
Metric Value
c 11
b 0
f 6
dl 0
loc 17
ccs 4
cts 8
cp 0.5
rs 9.4285
cc 2
eloc 10
nc 3
nop 1
crap 2.5
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
    public function process(ContainerBuilder $container)
20
    {
21
        $redis = $container->getDefinition('redis');
22 3
23
        $masterArguments = $this->getArguments($container, '');
24 3
25
        try {
26 3
            $slaveArguments = $this->getArguments($container, '.slave');
27
            $parameters = [$masterArguments, $slaveArguments];
28
            $options    = ['replication' => true];
29 3
30
            $redis->setArguments([$parameters, $options]);
31
        } catch (ParameterNotFoundException $e) {
32
            // master only
33
            $redis->setArguments([$masterArguments]);
34
        }
35
    }
36
37
    /**
38
     * @param ContainerBuilder $container
39
     * @param string $prefix
40
     * @return string
41 3
     */
42
    protected function getArguments(ContainerBuilder $container, $prefix)
43 3
    {
44
        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 3
    }
46
}
47