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/Field.php (1 issue)

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;
4
5
use PluginSimpleValidate\BaseAbstract\RuleMapping as AbstractRuleMapping;
6
use PluginSimpleValidate\Libraries\Language;
7
8
class Field extends \PluginSimpleValidate\BaseAbstract\Field implements \PluginSimpleValidate\Contracts\Field
9
{
10
    /**
11
     * @param Language $language
12
     * @return bool
13
     */
14 13 View Code Duplication
    public function isValid(Language $language) : bool
0 ignored issues
show
This method seems to be duplicated in 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...
15
    {
16
        // empty the `errors` array
17 13
        $this->emptyErrors();
18
19
        /** @var \PluginSimpleValidate\Contracts\Rule $rule */
20 13
        foreach ($this->rules as $ruleName => $rule) {
21 13
            if (!$rule->isValid($language, $this->value)) {
22 13
                $this->status = false;
23 13
                $this->errors[] = $rule->getError();
24
            }
25
        }
26
27 13
        if (empty($this->errors)) {
28 2
            $this->status = true;
29
        }
30
31 13
        return $this->status;
32
    }
33
34
    /**
35
     * @param string $rulesMethod
36
     * @param array $args
37
     * @return $this
38
     */
39 13
    public function addRules(string $rulesMethod, array $args = [])
40
    {
41 13
        $this->rules[$rulesMethod] = \PluginSimpleValidate\Libraries\RuleMapping::getInstance()->getRule($rulesMethod, $args);
42 13
        return $this;
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48 2
    public function getValue()
49
    {
50 2
        return $this->value;
51
    }
52
53
    /**
54
     * @param mixed $value
55
     * @return $this
56
     */
57 3
    public function setValue($value)
58
    {
59 3
        $this->value = $value;
60 3
        return $this;
61
    }
62
63
    /**
64
     * @param string $message
65
     * @return $this
66
     */
67 1
    public function isTrue(string $message = '')
68
    {
69 1
        $this->addRules(AbstractRuleMapping::VALIDATE_IS_TRUE, [static::VAR_MESSAGE => $message]);
70 1
        return $this;
71
    }
72
73
    /**
74
     * @return $this
75
     */
76 7
    public function required()
77
    {
78 7
        $this->addRules(AbstractRuleMapping::VALIDATE_REQUIRED);
79 7
        return $this;
80
    }
81
82
    /**
83
     * @return $this
84
     */
85 1
    public function notEmpty()
86
    {
87 1
        $this->addRules(AbstractRuleMapping::VALIDATE_IS_NOT_EMPTY);
88 1
        return $this;
89
    }
90
91
    /**
92
     * @return $this
93
     */
94 5
    public function validEmail()
95
    {
96 5
        $this->addRules(AbstractRuleMapping::VALIDATE_EMAIL);
97 5
        return $this;
98
    }
99
100
    /**
101
     * @param int|float|double|string $match
102
     * @return $this
103
     */
104 1
    public function equal($match)
105
    {
106 1
        $this->addRules(AbstractRuleMapping::VALIDATE_EQUAL, [static::VAR_MATCH => $match]);
107 1
        return $this;
108
    }
109
110
    /**
111
     * @return \PluginSimpleValidate\Contracts\Field
112
     */
113 1
    public function isNumber()
114
    {
115 1
        $this->addRules(AbstractRuleMapping::VALIDATE_NUMBER);
116 1
        return $this;
117
    }
118
119
    /**
120
     * @return \PluginSimpleValidate\Contracts\Field
121
     */
122
    public function isAlpha()
123
    {
124
        $this->addRules(AbstractRuleMapping::VALIDATE_ALPHA);
125
        return $this;
126
    }
127
128
    /**
129
     * @return \PluginSimpleValidate\Contracts\Field
130
     */
131 4
    public function isAlphaOrNumeric()
132
    {
133 4
        $this->addRules(AbstractRuleMapping::VALIDATE_ALPHA_OR_NUMERIC);
134 4
        return $this;
135
    }
136
137
    /**
138
     * @return \PluginSimpleValidate\Contracts\Field
139
     */
140
    public function isDecimal()
141
    {
142
        $this->addRules(AbstractRuleMapping::VALIDATE_DECIMAL);
143
        return $this;
144
    }
145
146
    /**
147
     * @return \PluginSimpleValidate\Contracts\Field
148
     */
149
    public function isInteger()
150
    {
151
        $this->addRules(AbstractRuleMapping::VALIDATE_INTEGER);
152
        return $this;
153
    }
154
155
    /**
156
     * @return \PluginSimpleValidate\Contracts\Field
157
     */
158
    public function isNatural()
159
    {
160
        $this->addRules(AbstractRuleMapping::VALIDATE_NATURAL_NUMBER);
161
        return $this;
162
    }
163
164
    /**
165
     * @return \PluginSimpleValidate\Contracts\Field
166
     */
167
    public function isNaturalNoZero()
168
    {
169
        $this->addRules(AbstractRuleMapping::VALIDATE_NATURAL_NO_ZERO_NUMBER);
170
        return $this;
171
    }
172
173
    /**
174
     * @param int|float|double $limit
175
     * @return $this
176
     */
177 1
    public function lessThan($limit)
178
    {
179 1
        $this->addRules(AbstractRuleMapping::VALIDATE_LESS_THAN, [static::VAR_LIMIT => $limit]);
180 1
        return $this;
181
    }
182
183
    /**
184
     * @param int|float|double $limit
185
     * @return \PluginSimpleValidate\Contracts\Field
186
     */
187
    public function greaterThan($limit)
188
    {
189
        $this->addRules(AbstractRuleMapping::VALIDATE_GREATER_THAN, [static::VAR_LIMIT => $limit]);
190
        return $this;
191
    }
192
193
    /**
194
     * @param int|float|double $limit
195
     * @return \PluginSimpleValidate\Contracts\Field
196
     */
197
    public function lessOrEqualThan($limit)
198
    {
199
        $this->addRules(AbstractRuleMapping::VALIDATE_LESS_OR_EQUAL_THAN, [static::VAR_LIMIT => $limit]);
200
        return $this;
201
    }
202
203
    /**
204
     * @param int|float|double $limit
205
     * @return \PluginSimpleValidate\Contracts\Field
206
     */
207
    public function greaterOrEqualThan($limit)
208
    {
209
        $this->addRules(AbstractRuleMapping::VALIDATE_GREATER_OR_EQUAL_THAN, [static::VAR_LIMIT => $limit]);
210
        return $this;
211
    }
212
213
    /**
214
     * @param int|float|double $lower
215
     * @param int|float|double $upper
216
     * @return $this
217
     */
218 1
    public function between($lower, $upper)
219
    {
220 1
        $this->addRules(AbstractRuleMapping::VALIDATE_BETWEEN, [static::VAR_LOWER_LIMIT => $lower, static::VAR_UPPER_LIMIT => $upper]);
221 1
        return $this;
222
    }
223
224
    /**
225
     * @param int|float|double $lower
226
     * @param int|float|double $upper
227
     * @return \PluginSimpleValidate\Contracts\Field
228
     */
229
    public function betweenOrEqual($lower, $upper)
230
    {
231
        $this->addRules(AbstractRuleMapping::VALIDATE_BETWEEN_OR_EQUAL_THAN, [static::VAR_LOWER_LIMIT => $lower, static::VAR_UPPER_LIMIT => $upper]);
232
        return $this;
233
    }
234
235
    /**
236
     * @param int|float|double $limit
237
     * @return \PluginSimpleValidate\Contracts\Field
238
     */
239
    public function length($limit)
240
    {
241
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH);
242
        return $this;
243
    }
244
245
    /**
246
     * @param int|float|double $limit
247
     * @return \PluginSimpleValidate\Contracts\Field
248
     */
249
    public function lengthLessThan($limit)
250
    {
251
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_LESS_THAN, [static::VAR_LIMIT => $limit]);
252
        return $this;
253
    }
254
255
    /**
256
     * @param int|float|double $limit
257
     * @return \PluginSimpleValidate\Contracts\Field
258
     */
259 4
    public function lengthGreaterThan($limit)
260
    {
261 4
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_GREATER_THAN, [static::VAR_LIMIT => $limit]);
262 4
        return $this;
263
    }
264
265
    /**
266
     * @param int|float|double $limit
267
     * @return \PluginSimpleValidate\Contracts\Field
268
     */
269
    public function lengthLessOrEqualThan($limit)
270
    {
271
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_LESS_OR_EQUAL_THAN, [static::VAR_LIMIT => $limit]);
272
        return $this;
273
    }
274
275
    /**
276
     * @param int|float|double $limit
277
     * @return \PluginSimpleValidate\Contracts\Field
278
     */
279 1
    public function lengthGreaterOrEqualThan($limit)
280
    {
281 1
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_GREATER_OR_EQUAL_THAN, [static::VAR_LIMIT => $limit]);
282 1
        return $this;
283
    }
284
285
    /**
286
     * @param int|float|double $lower
287
     * @param int|float|double $upper
288
     * @return \PluginSimpleValidate\Contracts\Field
289
     */
290
    public function lengthBetween($lower, $upper)
291
    {
292
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_BETWEEN, [static::VAR_LOWER_LIMIT => $lower, static::VAR_UPPER_LIMIT => $upper]);
293
        return $this;
294
    }
295
296
    /**
297
     * @param int|float|double $lower
298
     * @param int|float|double $upper
299
     * @return \PluginSimpleValidate\Contracts\Field
300
     */
301 1
    public function lengthBetweenOrEqual($lower, $upper)
302
    {
303 1
        $this->addRules(AbstractRuleMapping::VALIDATE_LENGTH_BETWEEN_OR_EQUAL_THAN, [static::VAR_LOWER_LIMIT => $lower, static::VAR_UPPER_LIMIT => $upper]);
304 1
        return $this;
305
    }
306
307
    /**
308
     * @param string $region
309
     * @return \PluginSimpleValidate\Contracts\Field
310
     */
311 1
    public function isValidPhone(string $region)
312
    {
313 1
        $this->addRules(AbstractRuleMapping::VALIDATE_PHONE_NUMBER, [static::VAR_REGION => $region]);
314 1
        return $this;
315
    }
316
}