Passed
Push — master ( 3ede18...19faf5 )
by Christopher
01:38
created

MinMaxTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 77
Duplicated Lines 20.78 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 13
c 3
b 1
f 0
lcom 1
cbo 0
dl 16
loc 77
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setMaxExclusive() 8 8 2
A setMaxInclusive() 0 4 1
A setMinExclusive() 8 8 2
A setMinInclusive() 0 4 1
A CheckMinMax() 0 9 3
A CheckMin() 0 6 2
A CheckMax() 0 6 2

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 AlgoWeb\xsdTypes\Facets;
3
4
//TODO: we need to extend this to handle dates.
5
trait MinMaxTrait
6
{
7
    /**
8
     * @Exclude
9
     * @var integer|double|\DateTime Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
10
     */
11
    private $minInclusive = null;
12
    /**
13
     * @Exclude
14
     * @var integer|double|\DateTime Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
15
     */
16
    private $maxInclusive = null;
17
18
    /**
19
     * @param integer|double|\DateTime $v Specifies the upper bounds for numeric values (the value must be less than this value)
20
     */
21 View Code Duplication
    public function setMaxExclusive($v)
1 ignored issue
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...
22
    {
23
        if (is_int($v)) {
24
            $this->maxInclusive = $v - 1;
25
        } else {
26
            $this->minInclusive = $v - 0.000001;
27
        }
28
    }
29
30
    /**
31
     * @param integer|double|\DateTime $v Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
32
     */
33
    public function setMaxInclusive($v)
34
    {
35
        $this->maxInclusive = $v;
36
    }
37
38
    /**
39
     * @param integer|double|\DateTime $v Specifies the lower bounds for numeric values (the value must be greater than this value)
40
     */
41 View Code Duplication
    public function setMinExclusive($v)
1 ignored issue
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...
42
    {
43
        if (is_int($v)) {
44
            $this->minInclusive = $v + 1;
45
        } else {
46
            $this->minInclusive = $v + 0.000001;
47
        }
48
    }
49
50
    /**
51
     * @param integer|double|\DateTime $v Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
52
     */
53
    public function setMinInclusive($v)
54
    {
55
        $this->minInclusive = $v;
56
    }
57
58
    public function CheckMinMax($v)
59
    {
60
        if (null != $this->minInclusive) {
61
            $this->CheckMin($v);
62
        }
63
        if (null != $this->maxInclusive) {
64
            $this->CheckMax($v);
65
        }
66
    }
67
68
    private function CheckMin($v)
69
    {
70
        if ($v < $this->minInclusive) {
71
            throw new \InvalidArgumentException("Value less than allowed min value " . __CLASS__);
72
        }
73
    }
74
75
    private function CheckMax($v)
76
    {
77
        if ($v > $this->maxInclusive) {
78
            throw new \InvalidArgumentException("Value greater than allowed max value " . __CLASS__);
79
        }
80
    }
81
}
82