Completed
Push — master ( b50394...04cf70 )
by Philip
02:32
created

AbstractParametrizedValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateParameterCount() 0 5 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
     * 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
     */
32
    protected function validateParameterCount($name, $parameterAmount, array $parameters) {
33
        if (count($parameters) !== $parameterAmount) {
34
            throw new ValidationException('"' . $name . '" expects ' . $parameterAmount . ' parameter.');
35
        }
36
    }
37
38
}
39