NumericRule   A
last analyzed

Complexity

Total Complexity 27

Size/Duplication

Total Lines 264
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 29
dl 0
loc 264
ccs 55
cts 55
cp 1
rs 10
c 2
b 1
f 1
wmc 27

27 Methods

Rating   Name   Duplication   Size   Complexity  
A nonPositive() 0 3 1
A lessThan() 0 3 1
A lessOrEqual() 0 3 1
A positive() 0 3 1
A truthy() 0 3 1
A __construct() 0 5 1
A greaterThan() 0 3 1
A falsy() 0 3 1
A greaterOrEqual() 0 3 1
A nonNegative() 0 3 1
A between() 0 3 1
A negative() 0 3 1
A inOpenInterval() 0 3 1
A inLeftHalfOpenInterval() 0 3 1
A even() 0 3 1
A nan() 0 3 1
A infinite() 0 3 1
A nonFractional() 0 3 1
A finite() 0 3 1
A inRightHalfOpenInterval() 0 3 1
A fractional() 0 3 1
A odd() 0 3 1
A notNan() 0 3 1
A string() 0 3 1
A float() 0 3 1
A number() 0 3 1
A integer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Factories\Checks\NumericCheckFactory;
8
use Smoren\Validator\Interfaces\NumericRuleInterface;
9
10
class NumericRule extends MixedRule implements NumericRuleInterface
11
{
12
    /**
13
     * @param string $name
14
     */
15 106
    public function __construct(string $name)
16
    {
17 106
        parent::__construct($name);
18
19 106
        $this->check(NumericCheckFactory::getNumericCheck(), true);
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     *
25
     * @return static
26
     */
27 2
    public function number(): self
28
    {
29 2
        return $this->check(NumericCheckFactory::getNumberCheck(), true);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * @return static
36
     */
37 2
    public function string(): self
38
    {
39 2
        return $this->check(NumericCheckFactory::getStringCheck(), true);
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     *
45
     * @return static
46
     */
47 71
    public function integer(): self
48
    {
49 71
        return $this->check(NumericCheckFactory::getIntegerCheck(), true);
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     *
55
     * @return static
56
     */
57 49
    public function float(): self
58
    {
59 49
        return $this->check(NumericCheckFactory::getFloatCheck(), true);
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     *
65
     * @return static
66
     */
67 6
    public function truthy(): self
68
    {
69 6
        return $this->check(NumericCheckFactory::getTruthyCheck());
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     *
75
     * @return static
76
     */
77 6
    public function falsy(): self
78
    {
79 6
        return $this->check(NumericCheckFactory::getFalsyCheck());
80
    }
81
82
    /**
83
     * {@inheritDoc}
84
     *
85
     * @return static
86
     */
87 62
    public function positive(): self
88
    {
89 62
        return $this->check(NumericCheckFactory::getPositiveCheck());
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     *
95
     * @return static
96
     */
97 6
    public function nonPositive(): self
98
    {
99 6
        return $this->check(NumericCheckFactory::getNonPositiveCheck());
100
    }
101
102
    /**
103
     * {@inheritDoc}
104
     *
105
     * @return static
106
     */
107 13
    public function nonNegative(): self
108
    {
109 13
        return $this->check(NumericCheckFactory::getNonNegativeCheck());
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     *
115
     * @return static
116
     */
117 6
    public function negative(): self
118
    {
119 6
        return $this->check(NumericCheckFactory::getNegativeCheck());
120
    }
121
122
    /**
123
     * {@inheritDoc}
124
     *
125
     * @return static
126
     */
127 16
    public function greaterThan($number): NumericRuleInterface
128
    {
129 16
        return $this->check(NumericCheckFactory::getGreaterThanCheck($number));
130
    }
131
132
    /**
133
     * {@inheritDoc}
134
     *
135
     * @return static
136
     */
137 6
    public function greaterOrEqual($number): NumericRuleInterface
138
    {
139 6
        return $this->check(NumericCheckFactory::getGreaterOrEqualCheck($number));
140
    }
141
142
    /**
143
     * {@inheritDoc}
144
     *
145
     * @return static
146
     */
147 18
    public function lessThan($number): NumericRuleInterface
148
    {
149 18
        return $this->check(NumericCheckFactory::getLessThanCheck($number));
150
    }
151
152
    /**
153
     * {@inheritDoc}
154
     *
155
     * @return static
156
     */
157 6
    public function lessOrEqual($number): NumericRuleInterface
158
    {
159 6
        return $this->check(NumericCheckFactory::getLessOrEqualCheck($number));
160
    }
161
162
    /**
163
     * {@inheritDoc}
164
     *
165
     * @return static
166
     */
167 27
    public function between($start, $end): self
168
    {
169 27
        return $this->check(NumericCheckFactory::getBetweenCheck($start, $end));
170
    }
171
172
    /**
173
     * {@inheritDoc}
174
     */
175 24
    public function inOpenInterval($start, $end): self
176
    {
177 24
        return $this->check(NumericCheckFactory::getInOpenIntervalCheck($start, $end));
178
    }
179
180
    /**
181
     * {@inheritDoc}
182
     */
183 2
    public function inLeftHalfOpenInterval($start, $end): self
184
    {
185 2
        return $this->check(NumericCheckFactory::getInLeftOpenIntervalCheck($start, $end));
186
    }
187
188
    /**
189
     * {@inheritDoc}
190
     */
191 2
    public function inRightHalfOpenInterval($start, $end): self
192
    {
193 2
        return $this->check(NumericCheckFactory::getInRightOpenIntervalCheck($start, $end));
194
    }
195
196
    /**
197
     * {@inheritDoc}
198
     *
199
     * @return static
200
     */
201 4
    public function fractional(): self
202
    {
203 4
        return $this->check(NumericCheckFactory::getFractionalCheck());
204
    }
205
206
    /**
207
     * {@inheritDoc}
208
     *
209
     * @return static
210
     */
211 7
    public function nonFractional(): self
212
    {
213 7
        return $this->check(NumericCheckFactory::getNonFractionalCheck());
214
    }
215
216
    /**
217
     * {@inheritDoc}
218
     *
219
     * @return static
220
     */
221 4
    public function finite(): self
222
    {
223 4
        return $this->check(NumericCheckFactory::getFiniteCheck());
224
    }
225
226
    /**
227
     * {@inheritDoc}
228
     *
229
     * @return static
230
     */
231 4
    public function infinite(): self
232
    {
233 4
        return $this->check(NumericCheckFactory::getInfiniteCheck());
234
    }
235
236
    /**
237
     * {@inheritDoc}
238
     *
239
     * @return static
240
     */
241 20
    public function even(): self
242
    {
243 20
        return $this->check(NumericCheckFactory::getEvenCheck());
244
    }
245
246
    /**
247
     * {@inheritDoc}
248
     *
249
     * @return static
250
     */
251 22
    public function odd(): self
252
    {
253 22
        return $this->check(NumericCheckFactory::getOddCheck());
254
    }
255
256
    /**
257
     * {@inheritDoc}
258
     *
259
     * @return static
260
     */
261 2
    public function nan(): self
262
    {
263 2
        return $this->check(NumericCheckFactory::getNanCheck());
264
    }
265
266
    /**
267
     * {@inheritDoc}
268
     *
269
     * @return static
270
     */
271 2
    public function notNan(): self
272
    {
273 2
        return $this->check(NumericCheckFactory::getNotNanCheck());
274
    }
275
}
276