Completed
Pull Request — master (#34)
by Krzysztof
06:00 queued 45s
created

CriteriaCollectionCompilerPass::processContext()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 17

Duplication

Lines 27
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 27
loc 27
ccs 12
cts 12
cp 1
rs 8.8571
cc 2
eloc 17
nc 2
nop 3
crap 2
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
8
/**
9
 * @author Krzysztof Gzocha <[email protected]>
10
 */
11 View Code Duplication
class CriteriaCollectionCompilerPass extends AbstractCompilerPass
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 5
    protected function processContext(
17
        $contextId,
18
        array &$context,
19
        ContainerBuilder $container
20
    ) {
21 5
        $config = $context[self::CRITERIA_COLLECTION_PARAMETER];
22 5
        $this->validateParameters($context, $config);
0 ignored issues
show
Documentation introduced by
$context is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
24
        // Service has higher priority than class parameter
25 5
        if (isset($config[self::SERVICE_PARAMETER])) {
26 1
            $this->checkIfServiceExists(
27
                $container,
28
                $contextId,
29 1
                $config[self::SERVICE_PARAMETER]
30
            );
31
32 1
            return $container->setDefinition(
33 1
                $this->buildServiceName($contextId, self::CRITERIA_COLLECTION_PARAMETER),
34 1
                $container->getDefinition($config[self::SERVICE_PARAMETER])
35
            );
36
        }
37
38 4
        return $container->setDefinition(
39 4
            $this->buildServiceName($contextId, self::CRITERIA_COLLECTION_PARAMETER),
40 4
            new Definition($config[self::CLASS_PARAMETER])
41
        );
42
    }
43
}
44