Completed
Pull Request — 1.x (#9)
by Dorian
44:57 queued 43:25
created

GreaterThanValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A validate() 6 6 3

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
namespace MetaHydrator\Validator;
3
4
use MetaHydrator\Exception\ValidationException;
5
6 View Code Duplication
class GreaterThanValidator extends AbstractValidator
0 ignored issues
show
Duplication introduced by
This class 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...
7
{
8
    /** @var mixed */
9
    protected $min;
10
11
    public function __construct($min, $errorMessage = "")
12
    {
13
        parent::__construct($errorMessage);
14
        $this->min = $min;
15
    }
16
17
    /**
18
     * @param mixed $value
19
     * @param $contextObject
20
     *
21
     * @throws ValidationException
22
     */
23
    public function validate($value, $contextObject = null)
24
    {
25
        if ($value !== null && $value < $this->min) {
26
            $this->throw();
27
        }
28
    }
29
}
30