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

CommonExpectations::isNotEqual()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dgame\Expectation;
4
5
/**
6
 * Class CommonExpectations
7
 * @package Dgame\Expectation
8
 */
9
final class CommonExpectations
10
{
11
    use ConditionTrait;
12
13
    /**
14
     * CommonExpectations constructor.
15
     *
16
     * @param $value
17
     */
18
    public function __construct($value)
19
    {
20
        $this->value = $value;
21
    }
22
23
    /**
24
     * @param callable $callback
25
     *
26
     * @return CommonExpectations
27
     */
28
    public function is(callable $callback): self
29
    {
30
        return $this->approveIf($callback($this->value));
31
    }
32
33
    /**
34
     * @param callable $callback
35
     *
36
     * @return CommonExpectations
37
     */
38
    public function isNot(callable $callback): self
39
    {
40
        return $this->approveIf(!$callback($this->value));
41
    }
42
43
    /**
44
     * @return CommonExpectations
45
     */
46
    public function isEmpty(): self
47
    {
48
        return $this->approveIf(empty($this->value));
49
    }
50
51
    /**
52
     * @return CommonExpectations
53
     */
54
    public function isNotEmpty(): self
55
    {
56
        return $this->approveIf(!empty($this->value));
57
    }
58
59
    /**
60
     * @return CommonExpectations
61
     */
62
    public function isNull(): self
63
    {
64
        return $this->isIdenticalTo(null);
65
    }
66
67
    /**
68
     * @return CommonExpectations
69
     */
70
    public function isNotNull(): self
71
    {
72
        return $this->isNotIdenticalTo(null);
73
    }
74
75
    /**
76
     * @param $value
77
     *
78
     * @return CommonExpectations
79
     */
80
    public function isEqual($value): self
81
    {
82
        return $this->approveIf($this->value == $value);
83
    }
84
85
    /**
86
     * @param $value
87
     *
88
     * @return CommonExpectations
89
     */
90
    public function isNotEqual($value): self
91
    {
92
        return $this->approveIf($this->value != $value);
93
    }
94
95
    /**
96
     * @param $value
97
     *
98
     * @return CommonExpectations
99
     */
100
    public function isIdenticalTo($value): self
101
    {
102
        return $this->approveIf($this->value === $value);
103
    }
104
105
    /**
106
     * @param $value
107
     *
108
     * @return CommonExpectations
109
     */
110
    public function isNotIdenticalTo($value): self
111
    {
112
        return $this->approveIf($this->value !== $value);
113
    }
114
115
    /**
116
     * @return IntegerExpectations
117
     */
118
    public function isInt(): IntegerExpectations
119
    {
120
        return new IntegerExpectations($this->value);
121
    }
122
123
    /**
124
     * @return FloatExpectations
125
     */
126
    public function isFloat(): FloatExpectations
127
    {
128
        return new FloatExpectations($this->value);
129
    }
130
131
    /**
132
     * @return ScalarExpectations
133
     */
134
    public function isScalar(): ScalarExpectations
135
    {
136
        return new ScalarExpectations($this->value);
137
    }
138
139
    /**
140
     * @return NumericExpectations
141
     */
142
    public function isNumeric(): NumericExpectations
143
    {
144
        return new NumericExpectations($this->value);
145
    }
146
147
    /**
148
     * @return StringExpectations
149
     */
150
    public function isString(): StringExpectations
151
    {
152
        return new StringExpectations($this->value);
153
    }
154
155
    /**
156
     * @return BooleanExpectations
157
     */
158
    public function isBool(): BooleanExpectations
159
    {
160
        return new BooleanExpectations($this->value);
161
    }
162
163
    /**
164
     * @return ArrayExpectations
165
     */
166
    public function isArray(): ArrayExpectations
167
    {
168
        return new ArrayExpectations($this->value);
169
    }
170
171
    /**
172
     * @return ObjectExpectations
173
     */
174
    public function isObject(): ObjectExpectations
175
    {
176
        return new ObjectExpectations($this->value);
177
    }
178
179
    /**
180
     * @param $object
181
     *
182
     * @return ObjectExpectations
183
     */
184
    public function isInstanceOf($object): ObjectExpectations
185
    {
186
        $expectation = new ObjectExpectations($this->value);
187
188
        return $expectation->isInstanceOf($object);
189
    }
190
191
    /**
192
     * @return CommonExpectations
193
     */
194
    public function isCallable(): self
195
    {
196
        return $this->is('is_callable');
197
    }
198
199
    /**
200
     * @return CommonExpectations
201
     */
202
    public function isDir(): self
203
    {
204
        return $this->is('is_dir');
205
    }
206
207
    /**
208
     * @return CommonExpectations
209
     */
210
    public function isFile(): self
211
    {
212
        return $this->is('is_file');
213
    }
214
215
    /**
216
     * @param float $lhs
217
     * @param float $rhs
218
     *
219
     * @return NumericExpectations
220
     */
221
    public function isBetween(float $lhs, float $rhs): NumericExpectations
222
    {
223
        $expectation = new NumericExpectations($this->value);
224
225
        return $expectation->isBetween($lhs, $rhs);
226
    }
227
228
    /**
229
     * @param float $value
230
     *
231
     * @return NumericExpectations
232
     */
233
    public function isBelow(float $value): NumericExpectations
234
    {
235
        $expectation = new NumericExpectations($this->value);
236
237
        return $expectation->isBelow($value);
238
    }
239
240
    /**
241
     * @param float $value
242
     *
243
     * @return NumericExpectations
244
     */
245
    public function isAbove(float $value): NumericExpectations
246
    {
247
        $expectation = new NumericExpectations($this->value);
248
249
        return $expectation->isAbove($value);
250
    }
251
252
    /**
253
     * @param float $value
254
     *
255
     * @return NumericExpectations
256
     */
257
    public function isBelowOrEqual(float $value): NumericExpectations
258
    {
259
        $expectation = new NumericExpectations($this->value);
260
261
        return $expectation->isBelowOrEqual($value);
262
    }
263
264
    /**
265
     * @param float $value
266
     *
267
     * @return NumericExpectations
268
     */
269
    public function isAboveOrEqual(float $value): NumericExpectations
270
    {
271
        $expectation = new NumericExpectations($this->value);
272
273
        return $expectation->isAboveOrEqual($value);
274
    }
275
276
    /**
277
     * @return NumericExpectations
278
     */
279
    public function isPositive(): NumericExpectations
280
    {
281
        $expectation = new NumericExpectations($this->value);
282
283
        return $expectation->isPositive();
284
    }
285
286
    /**
287
     * @return NumericExpectations
288
     */
289
    public function isNegative(): NumericExpectations
290
    {
291
        $expectation = new NumericExpectations($this->value);
292
293
        return $expectation->isNegative();
294
    }
295
296
    /**
297
     * @return IntegerExpectations
298
     */
299
    public function isEven(): IntegerExpectations
300
    {
301
        $expectation = new IntegerExpectations($this->value);
302
303
        return $expectation->isEven();
304
    }
305
306
    /**
307
     * @return IntegerExpectations
308
     */
309
    public function isOdd(): IntegerExpectations
310
    {
311
        $expectation = new IntegerExpectations($this->value);
312
313
        return $expectation->isOdd();
314
    }
315
316
    /**
317
     * @return BooleanExpectations
318
     */
319
    public function isTrue(): BooleanExpectations
320
    {
321
        $expectation = new BooleanExpectations($this->value);
322
323
        return $expectation->isTrue();
324
    }
325
326
    /**
327
     * @return BooleanExpectations
328
     */
329
    public function isFalse(): BooleanExpectations
330
    {
331
        $expectation = new BooleanExpectations($this->value);
332
333
        return $expectation->isFalse();
334
    }
335
336
    /**
337
     * @param string $pattern
338
     *
339
     * @return StringExpectations
340
     */
341
    public function match(string $pattern): StringExpectations
342
    {
343
        $expectation = new StringExpectations($this->value);
344
345
        return $expectation->match($pattern);
346
    }
347
348
    /**
349
     * @param array $values
350
     *
351
     * @return ArrayValueExpectations
352
     */
353
    public function isIn(array $values): ArrayValueExpectations
354
    {
355
        $expecation = new ArrayValueExpectations($this->value);
356
357
        return $expecation->isIn($values);
358
    }
359
360
    /**
361
     * @param array $values
362
     *
363
     * @return ArrayValueExpectations
364
     */
365
    public function isKeyOf(array $values): ArrayValueExpectations
366
    {
367
        $expecation = new ArrayValueExpectations($this->value);
368
369
        return $expecation->isKeyOf($values);
370
    }
371
372
    /**
373
     * @param int $length
374
     *
375
     * @return ArrayExpectations|StringExpectations
376
     */
377
    public function hasLength(int $length)
378
    {
379
        $expectation = new StringExpectations($this->value);
380
        if ($expectation->isApproved()) {
381
            return $expectation->hasLength($length);
382
        }
383
384
        $expecation = new ArrayExpectations($this->value);
385
386
        return $expecation->hasLength($length);
387
    }
388
}