Issues (20)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/helper/Validate.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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
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
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
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
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
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
}