Completed
Push — master ( a7f65d...f961c6 )
by Philip
02:28
created

validateParameterCount()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 8.8571
cc 5
eloc 3
nc 2
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Valdi package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Valdi\Validator;
13
14
use Valdi\ValidationException;
15
16
/**
17
 * Validator for parametrized validators.
18
 */
19
abstract class AbstractParametrizedValidator implements ValidatorInterface {
20
21
    /**
22
     * Throws an exception if the parameters don't fullfill the expected
23
     * parameter count.
24
     *
25
     * @param string $name
26
     * the name of the validator
27
     * @param integer $parameterAmount
28
     * the amount of expected parameters
29
     * @param string[] $parameters
30
     * the parameters
31
     * @param boolean $exact
32
     * whether the amount of parameters has to be exact (true) or whether it
33
     * might be greater (false)
34
     */
35
    protected function validateParameterCount($name, $parameterAmount, array $parameters, $exact = true) {
36
        if (($exact && count($parameters) !== $parameterAmount) xor (!$exact && count($parameters) < $parameterAmount)) {
37
            throw new ValidationException('"' . $name . '" expects ' . (!$exact ? 'at least ' : '') . $parameterAmount . ' parameter.');
38
        }
39
    }
40
41
}
42