Completed
Pull Request — master (#34)
by Krzysztof
04:27
created

ParametersValidator::validateParameters()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 9.3142
cc 3
eloc 14
nc 3
nop 2
crap 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 27
    public function validateParameters(
21
        $contextId,
22
        array &$config
23
    ) {
24 27
        if (isset($config[AbstractCompilerPass::CLASS_PARAMETER])) {
25 22
            return true;
26
        }
27
28 15
        if (isset($config[AbstractCompilerPass::SERVICE_PARAMETER])) {
29 14
            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