Validate.php ➔ greater_or_equal_than()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PluginSimpleValidate\helper\Validate;
4
5
use libphonenumber\NumberParseException;
6
use libphonenumber\PhoneNumber;
7
use libphonenumber\PhoneNumberUtil;
8
use PluginSimpleValidate\BaseAbstract\Field;
9
use PluginSimpleValidate\Exception\InvalidTypeParameter;
10
use function PluginSimpleValidate\helper\Cleaner\get_length;
11
use function PluginSimpleValidate\helper\Cleaner\is_valid_type_for_length;
12
use function PluginSimpleValidate\helper\Cleaner\trim_doubled_space;
13
14
if (! function_exists('is_true')) {
15
    function is_true($value)
16
    {
17 4
        return $value === true;
18
    }
19
}
20
21
if (! function_exists('is_number')) {
22
    function is_number($value)
23
    {
24 1
        return is_numeric($value);
25
    }
26
}
27
28
if (! function_exists('is_required')) {
29
    function is_required($value)
30
    {
31 8
        return $value !== '';
32
    }
33
}
34
35
if (! function_exists('is_not_empty')) {
36
    function is_not_empty($value)
37
    {
38 1
        return !empty(trim_doubled_space($value));
39
    }
40
}
41
42
if (! function_exists('is_valid_email')) {
43
    function is_valid_email($value)
44
    {
45 6
        return preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $value);
46
    }
47
}
48
49
if (! function_exists('is_alpha')) {
50
    function is_alpha($value)
51
    {
52
        return preg_match("/^([a-z])+$/i", $value);
53
    }
54
}
55
56
if (! function_exists('is_alpha_or_numeric')) {
57
    function is_alpha_or_numeric($value)
58
    {
59 3
        return preg_match("/^([a-z0-9])+$/i", $value);
60
    }
61
}
62
63
if (! function_exists('is_decimal')) {
64
    function is_decimal($value)
65
    {
66
        return preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $value);
67
    }
68
}
69
70
if (! function_exists('is_integer')) {
71
    function is_integer($value)
72
    {
73
        return preg_match('/^[\-+]?[0-9]+$/', $value);
74
    }
75
}
76
77
if (! function_exists('is_natural')) {
78
    function is_natural($value)
79
    {
80
        return preg_match('/^[0-9]+$/', $value);
81
    }
82
}
83
84
if (! function_exists('is_natural_no_zero')) {
85
    function is_natural_no_zero($value)
86
    {
87
        return preg_match('/^[1-9]+[0]*$/', $value);
88
    }
89
}
90
91
if (! function_exists('is_equal')) {
92
    function is_equal($value, array $args)
93
    {
94 1
        return $value === $args[Field::VAR_MATCH];
95
    }
96
}
97
98
if (! function_exists('less_than')) {
99
    function less_than($value, array $args)
100
    {
101 1
        return $value < $args[Field::VAR_LIMIT];
102
    }
103
}
104
105
if (! function_exists('greater_than')) {
106
    function greater_than($value, array $args)
107
    {
108
        return $value > $args[Field::VAR_LIMIT];
109
    }
110
}
111
112
if (! function_exists('less_or_equal_than')) {
113
    function less_or_equal_than($value, array $args)
114
    {
115
        return $value <= $args[Field::VAR_LIMIT];
116
    }
117
}
118
119
if (! function_exists('greater_or_equal_than')) {
120
    function greater_or_equal_than($value, array $args)
121
    {
122
        return $value >= $args[Field::VAR_LIMIT];
123
    }
124
}
125
126
if (! function_exists('between')) {
127
    function between($value, array $args)
128
    {
129 1
        return $value < $args[Field::VAR_UPPER_LIMIT] && $value > $args[Field::VAR_LOWER_LIMIT];
130
    }
131
}
132
133
if (! function_exists('between_or_equal')) {
134
    function between_or_equal($value, array $args)
135
    {
136
        return $value <= $args[Field::VAR_UPPER_LIMIT] && $value >= $args[Field::VAR_LOWER_LIMIT];
137
    }
138
}
139
140 View Code Duplication
if (! function_exists('length')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    function length($value, array $args)
142
    {
143
        return run_length_rule(
144
            $value,
145
            get_length($value) === $args[Field::VAR_LIMIT]
146
        );
147
    }
148
}
149
150 View Code Duplication
if (! function_exists('length_less_than')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
    function length_less_than($value, array $args)
152
    {
153
        return run_length_rule(
154
            $value,
155
            get_length($value) < $args[Field::VAR_LIMIT]
156
        );
157
    }
158
}
159
160 View Code Duplication
if (! function_exists('length_greater_than')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
    function length_greater_than($value, array $args)
162
    {
163 3
        return run_length_rule(
164 3
            $value,
165 3
            get_length($value) > $args[Field::VAR_LIMIT]
166
        );
167
    }
168
}
169
170 View Code Duplication
if (! function_exists('length_less_or_equal_than')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
    function length_less_or_equal_than($value, array $args)
172
    {
173
        return run_length_rule(
174
            $value,
175
            get_length($value) <= $args[Field::VAR_LIMIT]
176
        );
177
    }
178
}
179
180 View Code Duplication
if (! function_exists('length_greater_or_equal_than')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
    function length_greater_or_equal_than($value, array $args)
182
    {
183 1
        return run_length_rule(
184 1
            $value,
185 1
            get_length($value) >= $args[Field::VAR_LIMIT]
186
        );
187
    }
188
}
189
190 View Code Duplication
if (! function_exists('length_between')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191
    function length_between($value, array $args)
192
    {
193
        return run_length_rule(
194
            $value,
195
            get_length($value) < $args[Field::VAR_UPPER_LIMIT] && get_length($value) > $args[Field::VAR_LOWER_LIMIT]
196
        );
197
    }
198
}
199
200
201 View Code Duplication
if (! function_exists('length_between_or_equal')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
202
    function length_between_or_equal($value, array $args)
203
    {
204 2
        return run_length_rule(
205 2
            $value,
206 2
            get_length($value) <= $args[Field::VAR_UPPER_LIMIT] && get_length($value) >= $args[Field::VAR_LOWER_LIMIT]
207
        );
208
    }
209
}
210
211
if (! function_exists('valid_phone_number')) {
212
    function valid_phone_number($value, array $args)
213
    {
214
        try {
215 1
            $phoneUtil = PhoneNumberUtil::getInstance();
216
217
            /** @var PhoneNumber $phoneNumber */
218 1
            $phoneNumberProto = $phoneUtil->parse($value, $args[Field::VAR_REGION]);
219 1
            return $phoneUtil->isValidNumber(
220 1
                $phoneNumberProto
221
            );
222 1
        } catch (NumberParseException $exception) {
223 1
            return false;
224
        }
225
    }
226
}
227
228
if (! function_exists('run_length_rule')) {
229
    function run_length_rule($value, $result) {
230 5
        if (!is_valid_type_for_length($value)) {
231
            throw new InvalidTypeParameter();
232
        }
233
234 5
        return $result;
235
    }
236
}