Completed
Push — master ( 251e76...f62aa7 )
by
unknown
01:45
created

Validate.php ➔ length_greater_than()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 5
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PluginSimpleValidate\helper\Validate;
4
5
use PluginSimpleValidate\BaseAbstract\Field;
6
use PluginSimpleValidate\Exception\InvalidTypeParameter;
7
use function PluginSimpleValidate\helper\Cleaner\check_is_valid_type_for_length;
8
use function PluginSimpleValidate\helper\Cleaner\get_length;
9
use function PluginSimpleValidate\helper\Cleaner\is_valid_type_for_length;
10
use function PluginSimpleValidate\helper\Cleaner\trim_doubled_space;
11
12
if (! function_exists('is_true')) {
13
    function is_true($value)
14
    {
15 1
        return $value === true;
16
    }
17
}
18
19
if (! function_exists('is_number')) {
20
    function is_number($value)
21
    {
22
        return is_numeric($value);
23
    }
24
}
25
26
if (! function_exists('is_required')) {
27
    function is_required($value)
28
    {
29 4
        return !empty(trim_doubled_space($value));
30
    }
31
}
32
33
if (! function_exists('is_valid_email')) {
34
    function is_valid_email($value)
35
    {
36 3
        return preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $value);
37
    }
38
}
39
40
if (! function_exists('is_alpha')) {
41
    function is_alpha($value)
42
    {
43
        return preg_match("/^([a-z])+$/i", $value);
44
    }
45
}
46
47
if (! function_exists('is_alpha_or_numeric')) {
48
    function is_alpha_or_numeric($value)
49
    {
50 1
        return preg_match("/^([a-z0-9])+$/i", $value);
51
    }
52
}
53
54
if (! function_exists('is_decimal')) {
55
    function is_decimal($value)
56
    {
57
        return preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $value);
58
    }
59
}
60
61
if (! function_exists('is_integer')) {
62
    function is_integer($value)
63
    {
64
        return preg_match('/^[\-+]?[0-9]+$/', $value);
65
    }
66
}
67
68
if (! function_exists('is_natural')) {
69
    function is_natural($value)
70
    {
71
        return preg_match('/^[0-9]+$/', $value);
72
    }
73
}
74
75
if (! function_exists('is_natural_no_zero')) {
76
    function is_natural_no_zero($value)
77
    {
78
        return preg_match('/^[1-9]+[0]*$/', $value);
79
    }
80
}
81
82
if (! function_exists('is_equal')) {
83
    function is_equal($value, array $args)
84
    {
85 1
        return $value === $args[Field::VAR_MATCH];
86
    }
87
}
88
89
if (! function_exists('less_than')) {
90
    function less_than($value, array $args)
91
    {
92 1
        return $value < $args[Field::VAR_LIMIT];
93
    }
94
}
95
96
if (! function_exists('greater_than')) {
97
    function greater_than($value, array $args)
98
    {
99
        return $value > $args[Field::VAR_LIMIT];
100
    }
101
}
102
103
if (! function_exists('less_or_equal_than')) {
104
    function less_or_equal_than($value, array $args)
105
    {
106
        return $value <= $args[Field::VAR_LIMIT];
107
    }
108
}
109
110
if (! function_exists('greater_or_equal_than')) {
111
    function greater_or_equal_than($value, array $args)
112
    {
113
        return $value >= $args[Field::VAR_LIMIT];
114
    }
115
}
116
117
if (! function_exists('between')) {
118
    function between($value, array $args)
119
    {
120 1
        return $value < $args[Field::VAR_UPPER_LIMIT] && $value > $args[Field::VAR_LOWER_LIMIT];
121
    }
122
}
123
124
if (! function_exists('between_or_equal')) {
125
    function between_or_equal($value, array $args)
126
    {
127
        return $value <= $args[Field::VAR_UPPER_LIMIT] && $value >= $args[Field::VAR_LOWER_LIMIT];
128
    }
129
}
130
131 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...
132
    function length($value, array $args)
133
    {
134
        check_is_valid_type_for_length($value);
135
        return get_length($value) === $args[Field::VAR_LIMIT];
136
    }
137
}
138
139 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...
140
    function length_less_than($value, array $args)
141
    {
142
        check_is_valid_type_for_length($value);
143
        return get_length($value) < $args[Field::VAR_LIMIT];
144
    }
145
}
146
147 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...
148
    function length_greater_than($value, array $args)
149
    {
150 1
        check_is_valid_type_for_length($value);
151 1
        return get_length($value) > $args[Field::VAR_LIMIT];
152
    }
153
}
154
155 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...
156
    function length_less_or_equal_than($value, array $args)
157
    {
158
        check_is_valid_type_for_length($value);
159
        return get_length($value) <= $args[Field::VAR_LIMIT];
160
    }
161
}
162
163 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...
164
    function length_greater_or_equal_than($value, array $args)
165
    {
166
        check_is_valid_type_for_length($value);
167
        return get_length($value) >= $args[Field::VAR_LIMIT];
168
    }
169
}
170
171 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...
172
    function length_between($value, array $args)
173
    {
174
        check_is_valid_type_for_length($value);
175
        return get_length($value) < $args[Field::VAR_UPPER_LIMIT] && get_length($value) > $args[Field::VAR_LOWER_LIMIT];
176
    }
177
}
178
179
180 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...
181
    function length_between_or_equal($value, array $args)
182
    {
183
        check_is_valid_type_for_length($value);
184
        return get_length($value) <= $args[Field::VAR_UPPER_LIMIT] && get_length($value) >= $args[Field::VAR_LOWER_LIMIT];
185
    }
186
}