Passed
Pull Request — master (#22)
by Christopher
02:16
created

MinMaxTrait::checkMinMax()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 5
nc 4
nop 1
1
<?php
2
namespace AlgoWeb\xsdTypes\Facets;
3
4
trait MinMaxTrait
5
{
6
    /**
7
     * @Exclude
8
     * @var int|float|\DateTime|\DateInterval Specifies the lower bounds for numeric values (the value must be greater
9
     *                                        than or equal to this value)
10
     */
11
    private $minInclusive = null;
12
    /**
13
     * @Exclude
14
     * @var int|float|\DateTime|\DateInterval Specifies the upper bounds for numeric values (the value must be less
15
     *                                        than or equal to this value)
16
     */
17
    private $maxInclusive = null;
18
19
    /**
20
     * @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values (the value must be
21
     *                                             less than this value)
22
     */
23 View Code Duplication
    public function setMaxExclusive($v)
24
    {
25
        if (is_int($v)) {
26
            $this->maxInclusive = $v - 1;
27
        } else {
28
            $this->minInclusive = $v - 0.000001;
29
        }
30
    }
31
32
    /**
33
     * @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values
34
     *                                             (the value must be less than or equal to this value)
35
     */
36
    public function setMaxInclusive($v)
37
    {
38
        $this->maxInclusive = $v;
39
    }
40
41
    /**
42
     * @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values
43
     *                                             (the value must be greater than this value)
44
     */
45 View Code Duplication
    public function setMinExclusive($v)
46
    {
47
        if (is_int($v)) {
48
            $this->minInclusive = $v + 1;
49
        } else {
50
            $this->minInclusive = $v + 0.000001;
51
        }
52
    }
53
54
    /**
55
     * @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values
56
     *                                             (the value must be greater than or equal to this value)
57
     */
58
    public function setMinInclusive($v)
59
    {
60
        $this->minInclusive = $v;
61
    }
62
63
    public function checkMinMax($v)
64
    {
65
        if (null != $this->minInclusive) {
66
            $this->CheckMin($v);
67
        }
68
        if (null != $this->maxInclusive) {
69
            $this->CheckMax($v);
70
        }
71
    }
72
73
    private function CheckMin($v)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
74
    {
75
        if ($v < $this->minInclusive) {
76
            throw new \InvalidArgumentException('Value less than allowed min value ' . __CLASS__);
77
        }
78
    }
79
80
    private function CheckMax($v)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
81
    {
82
        if ($v > $this->maxInclusive) {
83
            throw new \InvalidArgumentException('Value greater than allowed max value ' . __CLASS__);
84
        }
85
    }
86
}
87