Completed
Push — master ( a9986e...3dd5b4 )
by Philip
02:24
created

Comparator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 9
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
compare() 0 1 ?
A validate() 9 9 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 comparing numeric values.
18
 */
19
abstract class Comparator implements ValidatorInterface {
20
21
    /**
22
     * Performs the comparison.
23
     *
24
     * @param mixed $a
25
     * the first number to compare
26
     * @param mixed $b
27
     * the second number to compare
28
     *
29
     * @return boolean
30
     * true if a compares to b
31
     */
32
    abstract protected function compare($a, $b);
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 View Code Duplication
    public function validate($value, array $parameters) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
39
        if (count($parameters) !== 1) {
40
            throw new ValidationException('"max" expects one parameter.');
41
        }
42
43
        return in_array($value, array('', null), true) ||
44
            (is_numeric($value) && $this->compare($value, $parameters[0]));
45
    }
46
}
47