Passed
Push — master ( eae2ea...251e76 )
by
unknown
01:43
created

Validate.php ➔ is_alpha_numeric()   A

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