Passed
Push — master ( 60236a...0f09f8 )
by Christopher
01:58
created

MinMaxTrait::CheckMinMax()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 8.8571
cc 5
eloc 7
nc 7
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Barnso
5
 * Date: 3/07/2017
6
 * Time: 10:19 PM
7
 */
8
9
namespace AlgoWeb\xsdTypes\Facets;
10
11
12
trait MinMaxTrait
13
{
14
    /**
15
     * @Exclude
16
     * @var integer Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
17
     */
18
    private $minInclusive = null;
19
    /**
20
     * @Exclude
21
     * @var integer Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
22
     */
23
    private $maxInclusive = null;
24
25
    /**
26
     * @param int $v Specifies the upper bounds for numeric values (the value must be less than this value)
27
     */
28
    public function setMaxExclusive($v)
29
    {
30
        $this->maxInclusive = $v - 1;
31
    }
32
33
    /**
34
     * @param int $v Specifies the upper bounds for numeric values (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 $v Specifies the lower bounds for numeric values (the value must be greater than this value)
43
     */
44
    public function setMinExclusive($v)
45
    {
46
        $this->minInclusive = $v - 1;
47
    }
48
49
    /**
50
     * @param int $v Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
51
     */
52
    public function setMinInclusive($v)
53
    {
54
        $this->minInclusive = $v;
55
56
    }
57
58
    public function CheckMinMax($v)
59
    {
60
        if (null != $this->minInclusive) {
61
            if ($v < $this->minInclusive) {
62
                throw new \InvalidArgumentException("value below allowed min value " . __CLASS__);
63
            }
64
        }
65
        if (null != $this->maxInclusive) {
66
            if ($v > $this->maxInclusive) {
67
                throw new \InvalidArgumentException(" value above allowed max value " . __CLASS__);
68
            }
69
        }
70
    }
71
}