Completed
Push — master ( 9d6b90...0a141c )
by Randy
11:08
created

NumericExpectations::isPositive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dgame\Expectation;
4
5
/**
6
 * Class NumericExpectations
7
 * @package Dgame\Expectation
8
 */
9
class NumericExpectations extends ScalarExpectations
10
{
11
    /**
12
     * NumericExpectations constructor.
13
     *
14
     * @param $value
15
     */
16
    public function __construct($value)
17
    {
18
        if ($this->isNumeric($value)) {
19
            parent::__construct($value);
20
        }
21
    }
22
23
    /**
24
     * @param $value
25
     *
26
     * @return bool
27
     */
28
    final protected function isNumeric($value): bool
29
    {
30
        return $this->approveIf(is_numeric($value))->isApproved();
31
    }
32
33
    /**
34
     * @param float $lhs
35
     * @param float $rhs
36
     *
37
     * @return NumericExpectations
38
     */
39
    public function isBetween(float $lhs, float $rhs): self
40
    {
41
        return $this->approveIf($this->value >= $lhs && $this->value <= $rhs);
42
    }
43
44
    /**
45
     * @param float $value
46
     *
47
     * @return NumericExpectations
48
     */
49
    public function isBelow(float $value): self
50
    {
51
        return $this->approveIf($this->value < $value);
52
    }
53
54
    /**
55
     * @param float $value
56
     *
57
     * @return NumericExpectations
58
     */
59
    public function isAbove(float $value): self
60
    {
61
        return $this->approveIf($this->value > $value);
62
    }
63
64
    /**
65
     * @param float $value
66
     *
67
     * @return NumericExpectations
68
     */
69
    public function isBelowOrEqual(float $value): self
70
    {
71
        return $this->approveIf($this->value <= $value);
72
    }
73
74
    /**
75
     * @param float $value
76
     *
77
     * @return NumericExpectations
78
     */
79
    public function isAboveOrEqual(float $value): self
80
    {
81
        return $this->approveIf($this->value >= $value);
82
    }
83
84
    /**
85
     * @return NumericExpectations
86
     */
87
    public function isPositive(): self
88
    {
89
        return $this->isAboveOrEqual(0);
90
    }
91
92
    /**
93
     * @return NumericExpectations
94
     */
95
    public function isNegative(): self
96
    {
97
        return $this->isBelow(0);
98
    }
99
}