AbstractParametrizedValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
dl 0
loc 17
ccs 3
cts 3
cp 1
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateParameterCount() 0 4 2
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
    /**
23
     * Throws an exception if the parameters don't fulfill the expected
24
     * parameter count.
25
     *
26
     * @param string $name the name of the validator
27
     * @param integer $parameterAmount the amount of expected parameters
28
     * @param string[] $parameters the parameters
29
     *
30
     * @throws ValidationException - thrown if the amount of parameters isn't the expected one
31
     */
32 15
    protected function validateParameterCount($name, $parameterAmount, array $parameters)
33
    {
34 15
        if (count($parameters) !== $parameterAmount) {
35 1
            throw new ValidationException('"' . $name . '" expects ' . $parameterAmount . ' parameter.');
36
        }
37 15
    }
38
39
}
40