Passed
Pull Request — master (#6)
by Julien
03:04
created

FloatCheck::isGreaterThan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Pitchart\Phlunit\Checks;
4
5
use PHPUnit\Framework\Assert;
6
use Pitchart\Phlunit\Checks\Mixin\TypeCheck;
7
use Pitchart\Phlunit\Checks\Mixin\WithMessage;
8
9
/**
10
 * Class FloatCheck
11
 *
12
 * @package Pitchart\Phlunit\Checks
13
 *
14
 * @author Julien VITTE <[email protected]>
15
 *
16
 * @implements FluentCheck<double>
17
 */
18
class FloatCheck implements FluentCheck
19
{
20 1
    use WithMessage, TypeCheck;
21
22
    /**
23
     * @var float
24
     */
25
    private $value;
26
27
    /**
28
     * @var
29
     */
30
    private $delta;
31
32
    /**
33
     * FloatCheck constructor.
34
     *
35
     * @param float $value
36
     */
37 8
    public function __construct(float $value)
38
    {
39 8
        $this->value = $value;
40 8
    }
41
42
    /**
43
     * @param float $expected
44
     *
45
     * @return GenericCheck
46
     */
47 2
    public function isEqualTo(float $expected): self
48
    {
49 2
        if ($this->delta) {
50 1
            Assert::assertEqualsWithDelta($expected, $this->value, $this->delta, $this->message);
51
        } else {
52 1
            Assert::assertSame($expected, $this->value, $this->message);
53
        }
54 2
        $this->resetMessage();
55 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Pitchart\Phlunit\Checks\FloatCheck which is incompatible with the documented return type Pitchart\Phlunit\Checks\GenericCheck.
Loading history...
56
    }
57
58
    /**
59
     * @param float $expected
60
     *
61
     * @return GenericCheck
62
     */
63 2
    public function isNotEqualTo(float $expected): self
64
    {
65 2
        if ($this->delta) {
66 1
            Assert::assertNotEqualsWithDelta($expected, $this->value, $this->delta, $this->message);
67
        } else {
68 2
            Assert::assertNotSame($expected, $this->value, $this->message);
69
        }
70 2
        $this->resetMessage();
71 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Pitchart\Phlunit\Checks\FloatCheck which is incompatible with the documented return type Pitchart\Phlunit\Checks\GenericCheck.
Loading history...
72
    }
73
74 1
    public function isEmpty(): self
75
    {
76 1
        Assert::assertEmpty($this->value, $this->message);
77 1
        $this->resetMessage();
78 1
        return $this;
79
    }
80
81 1
    public function isNotEmpty(): self
82
    {
83 1
        Assert::assertNotEmpty($this->value, $this->message);
84 1
        $this->resetMessage();
85 1
        return $this;
86
    }
87
88 1
    public function isGreaterThan(float $expected): self
89
    {
90 1
        Assert::assertGreaterThan($expected, $this->value, $this->message);
91 1
        $this->resetMessage();
92 1
        return $this;
93
    }
94
95 1
    public function isGreaterThanOrEqualTo(float $expected): self
96
    {
97 1
        Assert::assertGreaterThanOrEqual($expected, $this->value, $this->message);
98 1
        $this->resetMessage();
99 1
        return $this;
100
    }
101
102 1
    public function isLessThan(float $expected): self
103
    {
104 1
        Assert::assertLessThan($expected, $this->value, $this->message);
105 1
        $this->resetMessage();
106 1
        return $this;
107
    }
108
109 1
    public function isLessThanOrEqualTo(float $expected): self
110
    {
111 1
        Assert::assertLessThanOrEqual($expected, $this->value, $this->message);
112 1
        $this->resetMessage();
113 1
        return $this;
114
    }
115
116 1
    public function withDelta(float $delta)
117
    {
118 1
        $this->delta = $delta;
119 1
        return $this;
120
    }
121
122 1
    public function strictly()
123
    {
124 1
        return $this->withDelta(0.0);
125
    }
126
}
127