MinMaxTrait::setMinInclusive()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace AlgoWeb\xsdTypes\Facets;
3
4
trait MinMaxTrait
5
{
6
    /**
7
     * @Exclude
8
     * @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the lower bounds for numeric values
9
     *                                                                     (the value must be greater than or equal to
10
     *                                                                     this value)
11
     */
12
    private $minInclusive = null;
13
    /**
14
     * @Exclude
15
     * @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values
16
     *                                                                     (the value must be less than or equal to this
17
     *                                                                     value)
18
     */
19
    private $maxInclusive = null;
20
21
    /**
22
     * @Exclude
23
     * @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values
24
     *                                                                     (the value must be less than or equal to this
25
     *                                                                     value)
26
     */
27
    private $minExclusive = null;
28
    /**
29
     * @Exclude
30
     * @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values
31
     *                                                                     (the value must be less than or equal to this
32
     *                                                                     value)
33
     */
34
    private $maxExclusive = null;
35
36
    /**
37
     * @param int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender $newMax Specifies the upper bounds for numeric
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
     *                                                                               values (the value must be less than this
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
39
     *                                                                               value)
40
     */
41
    public function setMaxExclusive($newMax)
42
    {
43
        $this->maxExclusive = $newMax;
44
    }
45
46
    /**
47
     * @param int|float|\DateTime|\DateInterval $newMax Specifies the upper bounds for numeric values
48
     *                                                  (the value must be less than or equal to this value)
49
     */
50
    public function setMaxInclusive($newMax)
51
    {
52
        $this->maxInclusive = $newMax;
0 ignored issues
show
Documentation Bug introduced by
It seems like $newMax can also be of type object<DateInterval>. However, the property $maxInclusive is declared as type integer|double|object<Da...illaryClasses\Calender>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
53
    }
54
    /**
55
     * @param int|float|\DateTime|\DateInterval $newMin Specifies the lower bounds for numeric values
56
     *                                                  (the value must be greater than this value)
57
     */
58
    public function setMinExclusive($newMin)
59
    {
60
        $this->minExclusive = $newMin;
0 ignored issues
show
Documentation Bug introduced by
It seems like $newMin can also be of type object<DateInterval>. However, the property $minExclusive is declared as type integer|double|object<Da...illaryClasses\Calender>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
61
    }
62
63
    /**
64
     * @param int|float|\DateTime|\DateInterval $newMin Specifies the lower bounds for numeric values
65
     *                                                  (the value must be greater than or equal to this value)
66
     */
67
    public function setMinInclusive($newMin)
68
    {
69
        $this->minInclusive = $newMin;
0 ignored issues
show
Documentation Bug introduced by
It seems like $newMin can also be of type object<DateInterval>. However, the property $minInclusive is declared as type integer|double|object<Da...illaryClasses\Calender>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
70
    }
71
72
    public function checkMinMax($value)
73
    {
74
        if (null !== $this->minInclusive) {
75
            $this->checkMin($value);
76
        }
77
        if (null !== $this->maxInclusive) {
78
            $this->checkMax($value);
79
        }
80
    }
81
82
    private function checkMin($value)
83
    {
84
        if ($value < $this->minInclusive) {
85
            throw new \InvalidArgumentException('Value less than allowed min value ' . get_class($this));
86
        }
87
    }
88
89
    private function checkMax($value)
90
    {
91
        if ($value > $this->maxInclusive) {
92
            throw new \InvalidArgumentException('Value greater than allowed max value ' . get_class($this));
93
        }
94
    }
95
}
96