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

ParametersValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateParameters() 0 21 3
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
6
7
/**
8
 * @author Krzysztof Gzocha <[email protected]>
9
 */
10
class ParametersValidator
11
{
12
    /**
13
     * @param string $contextId
14
     * @param array  $config
15
     *
16
     * @return bool
17
     *
18
     * @throws InvalidDefinitionException
19
     */
20 22
    public function validateParameters(
21
        $contextId,
22
        array &$config
23
    ) {
24 22
        if (isset($config[AbstractCompilerPass::CLASS_PARAMETER])) {
25 19
            return true;
26
        }
27
28 12
        if (isset($config[AbstractCompilerPass::SERVICE_PARAMETER])) {
29 11
            return true;
30
        }
31
32 1
        throw new InvalidDefinitionException(sprintf(
33
            'You have to specify "%s" or "%s" parameters for %s '.
34 1
            'in searching context "%s".',
35 1
            AbstractCompilerPass::CLASS_PARAMETER,
36 1
            AbstractCompilerPass::SERVICE_PARAMETER,
37 1
            AbstractCompilerPass::CRITERIA_COLLECTION_PARAMETER,
38
            $contextId
39
        ));
40
    }
41
}
42