Completed
Push — master ( bdad9e...765e29 )
by Philip
02:16
created

Comparator::allNumeric()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
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
/**
15
 * Validator for comparing values.
16
 */
17
abstract class Comparator extends ParametrizedValidator {
18
19
    /**
20
     * Holds the amount of parameters.
21
     */
22
    protected $amountOfParameters = 1;
23
24
    /**
25
     * Holds the type of the validator.
26
     */
27
    protected $type;
28
29
    /**
30
     * Performs the comparison.
31
     *
32
     * @param mixed $a
0 ignored issues
show
Bug introduced by
There is no parameter named $a. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     * the first value to compare
34
     * @param mixed $parameters
35
     * the values to compare
36
     *
37
     * @return boolean
38
     * true if a compares to the values
39
     */
40
    abstract protected function compare($value, $parameters);
41
42
    /**
43
     * Checks whether all given parameters are numeric.
44
     *
45
     * @return boolean
46
     * true if all values are numeric
47
     */
48
    protected function allNumeric() {
49
        foreach (func_get_args() as $value) {
50
            if (!is_numeric($value)) {
51
                return false;
52
            }
53
        }
54
        return true;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function validate($value, array $parameters) {
61
62
        $this->validateParameterCount($this->type, $this->amountOfParameters, $parameters);
63
64
        return in_array($value, array('', null), true) ||
65
            $this->compare($value, $parameters);
66
    }
67
}
68