Completed
Push — master ( 96468a...a7f65d )
by Philip
02:55
created

validateParameterCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 3
Ratio 60 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 3
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 3
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 View Code Duplication
        if (count($parameters) !== $parameterAmount) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            throw new ValidationException('"' . $name . '" expects ' . $parameterAmount . ' parameter.');
35
        }
36
    }
37
38
    /**
39
     * Throws an exception if the parameters don't fullfill the expected
40
     * minimum parameter count.
41
     *
42
     * @param string $name
43
     * the name of the validator
44
     * @param integer $parameterAmount
45
     * the amount of expected parameters
46
     * @param string[] $parameters
47
     * the parameters
48
     */
49
    protected function validateMinParameterCount($name, $parameterAmount, array $parameters) {
50 View Code Duplication
        if (count($parameters) < $parameterAmount) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            throw new ValidationException('"' . $name . '" expects at least ' . $parameterAmount . ' parameter.');
52
        }
53
    }
54
}
55