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

MinMaxTrait::CheckMax()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
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