Passed
Push — master ( 7096b5...38b3e5 )
by Maxim
02:27
created

Predicates::whereMoreThan()   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 eachEven(): Closure
35
    {
36 1
        $isEven = false;
37
        return static function () use (& $isEven) {
38 1
            $res = $isEven;
39 1
            $isEven = !$isEven;
40
41 1
            return $res;
42 1
        };
43
    }
44
45 1
    public static function nth($number): Closure
46
    {
47 1
        $counter = 0;
48
        return static function () use ($number, & $counter) {
49 1
            $res = ++$counter % $number === 0;
50 1
            if ($res) {
51 1
                $counter = 0;
52
            }
53 1
            return $res;
54 1
        };
55
    }
56
57 1
    public static function equal($value): Closure
58
    {
59
        return static function ($el) use ($value): bool {
60 1
            return $el === $value;
61 1
        };
62
    }
63
64 2
    public static function lessThan($value): Closure
65
    {
66
        return static function ($el) use ($value): bool {
67 1
            return $el < $value;
68 2
        };
69
    }
70
71 3
    public static function lessOrEqual($value): Closure
72
    {
73
        return static function ($el) use ($value): bool {
74 2
            return $el <= $value;
75 3
        };
76
    }
77
78 1
    public static function moreThan($value): Closure
79
    {
80
        return static function ($el) use ($value): bool {
81 1
            return $el > $value;
82 1
        };
83
    }
84
85 3
    public static function moreOrEqual($value): Closure
86
    {
87
        return static function ($el) use ($value): bool {
88 3
            return $el >= $value;
89 3
        };
90
    }
91
92 1
    public static function not($value): Closure
93
    {
94
        return static function ($el) use ($value): bool {
95 1
            return $el !== $value;
96 1
        };
97
    }
98
99 1
    public static function in(array $values): Closure
100
    {
101
        return static function ($el) use ($values): bool {
102 1
            return in_array($el, $values, true);
103 1
        };
104
    }
105
106 1
    public static function notIn(array $values): Closure
107
    {
108
        return static function ($el) use ($values): bool {
109 1
            return !in_array($el, $values, true);
110 1
        };
111
    }
112
113 1
    public static function where(string $property, $value): Closure
114
    {
115
        return static function ($ob) use ($property, $value) {
116 1
            return $value === ObjectFunctions::getPropertyValue($ob, $property);
117 1
        };
118
    }
119
120 1
    public static function whereNot(string $property, $value): Closure
121
    {
122
        return static function ($ob) use ($property, $value) {
123 1
            return $value !== ObjectFunctions::getPropertyValue($ob, $property);
124 1
        };
125
    }
126
127 1
    public static function whereIn(string $property, array $values): Closure
128
    {
129
        return static function ($ob) use ($property, $values) {
130 1
            return in_array(ObjectFunctions::getPropertyValue($ob, $property), $values, true);
131 1
        };
132
    }
133
134 1
    public static function whereNotIn(string $property, array $values): Closure
135
    {
136
        return static function ($ob) use ($property, $values) {
137 1
            return !in_array(ObjectFunctions::getPropertyValue($ob, $property), $values, true);
138 1
        };
139
    }
140
141 1
    public static function whereMoreThan(string $property, $value): Closure
142
    {
143
        return static function (object $ob) use ($property, $value) {
144 1
            return ObjectFunctions::getPropertyValue($ob, $property) > $value;
145 1
        };
146
    }
147
148 1
    public static function whereLessThan(string $property, $value): Closure
149
    {
150
        return static function (object $ob) use ($property, $value) {
151 1
            return ObjectFunctions::getPropertyValue($ob, $property) < $value;
152 1
        };
153
    }
154
155 1
    public static function whereMoreOrEqual(string $property, $value): Closure
156
    {
157
        return static function (object $ob) use ($property, $value) {
158 1
            return ObjectFunctions::getPropertyValue($ob, $property) >= $value;
159 1
        };
160
    }
161
162 1
    public static function whereLessOrEqual(string $property, $value): Closure
163
    {
164
        return static function (object $ob) use ($property, $value) {
165 1
            return ObjectFunctions::getPropertyValue($ob, $property) <= $value;
166 1
        };
167
    }
168
}
169