Passed
Push — master ( 98efde...7096b5 )
by Maxim
02:27
created

Predicates::whereNot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @author Maxim Sokolovsky
4
 */
5
6
namespace WS\Utils\Collections\Functions;
7
8
use Closure;
9
10
class Predicates
11
{
12
13 1
    public static function lock(): Closure
14
    {
15
        return static function (): bool {
16 1
            return false;
17 1
        };
18
    }
19
20 1
    public static function notNull(): Closure
21
    {
22
        return static function ($el): bool {
23 1
            return $el !== null;
24 1
        };
25
    }
26
27 3
    public static function notResistance(): Closure
28
    {
29
        return static function (): bool {
30 3
            return true;
31 3
        };
32
    }
33
34 1
    public static function equal($value): Closure
35
    {
36
        return static function ($el) use ($value): bool {
37 1
            return $el === $value;
38 1
        };
39
    }
40
41 2
    public static function lessThan($value): Closure
42
    {
43
        return static function ($el) use ($value): bool {
44 1
            return $el < $value;
45 2
        };
46
    }
47
48 3
    public static function lessOrEqual($value): Closure
49
    {
50
        return static function ($el) use ($value): bool {
51 2
            return $el <= $value;
52 3
        };
53
    }
54
55 1
    public static function moreThan($value): Closure
56
    {
57
        return static function ($el) use ($value): bool {
58 1
            return $el > $value;
59 1
        };
60
    }
61
62 3
    public static function moreOrEqual($value): Closure
63
    {
64
        return static function ($el) use ($value): bool {
65 3
            return $el >= $value;
66 3
        };
67
    }
68
69 1
    public static function not($value): Closure
70
    {
71
        return static function ($el) use ($value): bool {
72 1
            return $el !== $value;
73 1
        };
74
    }
75
76 1
    public static function in(array $values): Closure
77
    {
78
        return static function ($el) use ($values): bool {
79 1
            return in_array($el, $values, true);
80 1
        };
81
    }
82
83 1
    public static function notIn(array $values): Closure
84
    {
85
        return static function ($el) use ($values): bool {
86 1
            return !in_array($el, $values, true);
87 1
        };
88
    }
89
90 1
    public static function where(string $property, $value): Closure
91
    {
92
        return static function ($ob) use ($property, $value) {
93 1
            return $value === ObjectFunctions::getPropertyValue($ob, $property);
94 1
        };
95
    }
96
97 1
    public static function whereNot(string $property, $value): Closure
98
    {
99
        return static function ($ob) use ($property, $value) {
100 1
            return $value !== ObjectFunctions::getPropertyValue($ob, $property);
101 1
        };
102
    }
103
104 1
    public static function whereIn(string $property, array $values): Closure
105
    {
106
        return static function ($ob) use ($property, $values) {
107 1
            return in_array(ObjectFunctions::getPropertyValue($ob, $property), $values, true);
108 1
        };
109
    }
110
111 1
    public static function whereNotIn(string $property, array $values): Closure
112
    {
113
        return static function ($ob) use ($property, $values) {
114 1
            return !in_array(ObjectFunctions::getPropertyValue($ob, $property), $values, true);
115 1
        };
116
    }
117
118 1
    public static function whereMoreThan(string $property, $value): Closure
119
    {
120
        return static function (object $ob) use ($property, $value) {
121 1
            return ObjectFunctions::getPropertyValue($ob, $property) > $value;
122 1
        };
123
    }
124
125 1
    public static function whereLessThan(string $property, $value): Closure
126
    {
127
        return static function (object $ob) use ($property, $value) {
128 1
            return ObjectFunctions::getPropertyValue($ob, $property) < $value;
129 1
        };
130
    }
131
132 1
    public static function whereMoreOrEqual(string $property, $value): Closure
133
    {
134
        return static function (object $ob) use ($property, $value) {
135 1
            return ObjectFunctions::getPropertyValue($ob, $property) >= $value;
136 1
        };
137
    }
138
139 1
    public static function whereLessOrEqual(string $property, $value): Closure
140
    {
141
        return static function (object $ob) use ($property, $value) {
142 1
            return ObjectFunctions::getPropertyValue($ob, $property) <= $value;
143 1
        };
144
    }
145
}
146