Completed
Push — master ( 37a719...4fa3c4 )
by Philip
02:36
created

AbstractComparator::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
nc 3
cc 3
eloc 5
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 AbstractComparator 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 $value
33
     * the first value to compare
34
     * @param mixed $parameters
35
     * the values to compare
36
     *
37
     * @return boolean
38
     * true if value compares to the parameters
39
     */
40
    abstract protected function compare($value, $parameters);
0 ignored issues
show
Coding Style introduced by
function compare() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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() {
0 ignored issues
show
Coding Style introduced by
function allNumeric() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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 isValid($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