ValidatesAttributes   B
last analyzed

Complexity

Total Complexity 51

Size/Duplication

Total Lines 431
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 431
ccs 86
cts 86
cp 1
rs 7.92
c 0
b 0
f 0
wmc 51

30 Methods

Rating   Name   Duplication   Size   Complexity  
A validateDateBefore() 0 3 1
A validateRequired() 0 3 1
A validateIp() 0 3 1
A validateString() 0 3 1
A validateDate() 0 3 1
A validateEmail() 0 3 1
A validateRequiredIf() 0 6 3
A validateNumeric() 0 3 2
A validateBoolean() 0 3 1
A validateRequiredWith() 0 3 2
A validateRequiredUnless() 0 6 3
A validateAccept() 0 3 1
A validateInteger() 0 3 1
A validateConfirm() 0 3 1
B validateRange() 0 22 8
A validateIn() 0 3 1
A validateMax() 0 3 1
A validateDateAfter() 0 3 1
A validateSize() 0 6 2
A validateJson() 0 3 1
A validateArray() 0 3 1
A validateUrl() 0 3 1
A validateMin() 0 3 1
A validateRequiredWithout() 0 3 2
A validateDiff() 0 5 2
A validateNullable() 0 3 1
A validateDateFormat() 0 3 1
A getSize() 0 13 6
A validateFloat() 0 3 1
A validateRegex() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like ValidatesAttributes often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ValidatesAttributes, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @author: RunnerLee
4
 * @email: [email protected]
5
 * @time: 2018-12
6
 */
7
8
namespace Runner\Validator\Concerns;
9
10
use Runner\Validator\Validator;
11
12
trait ValidatesAttributes
13
{
14
    /**
15
     * @param $field
16
     * @param $value
17
     * @param array     $parameters
18
     * @param Validator $validator
19
     *
20
     * @return bool
21
     */
22 1
    public function validateAccept($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function validateAccept($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function validateAccept($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function validateAccept(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24 1
        return in_array(strtolower($value), ['yes', 'on', '1', 1, true], true);
25
    }
26
27
    /**
28
     * @param $field
29
     * @param $value
30
     * @param array     $parameters
31
     * @param Validator $validator
32
     *
33
     * @return bool
34
     */
35 1
    public function validateNumeric($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    public function validateNumeric($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    public function validateNumeric($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    public function validateNumeric(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37 1
        return false !== filter_var($value, FILTER_VALIDATE_INT) || false !== filter_var($value, FILTER_VALIDATE_FLOAT);
38
    }
39
40
    /**
41
     * @param $field
42
     * @param $value
43
     * @param array     $parameters
44
     * @param Validator $validator
45
     *
46
     * @return bool
47
     */
48 2
    public function validateInteger($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function validateInteger(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function validateInteger($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function validateInteger($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50 2
        return false !== filter_var($value, FILTER_VALIDATE_INT);
51
    }
52
53
    /**
54
     * @param $field
55
     * @param $value
56
     * @param array     $parameters
57
     * @param Validator $validator
58
     *
59
     * @return bool
60
     */
61 1
    public function validateFloat($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function validateFloat($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function validateFloat(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function validateFloat($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63 1
        return false !== filter_var($value, FILTER_VALIDATE_FLOAT);
64
    }
65
66
    /**
67
     * @param $field
68
     * @param $value
69
     * @param array     $parameters
70
     * @param Validator $validator
71
     *
72
     * @return bool
73
     */
74 2
    public function validateSize($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
    public function validateSize($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76 2
        $size = filter_var($parameters[0], FILTER_VALIDATE_INT);
77 2
        false === $size && $size = filter_var($parameters[0], FILTER_VALIDATE_FLOAT);
78
79 2
        return $this->getSize($field, $value) === $size;
80
    }
81
82
    /**
83
     * @param $field
84
     * @param $value
85
     * @param array     $parameters
86
     * @param Validator $validator
87
     *
88
     * @return bool
89
     */
90 1
    public function validateUrl($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function validateUrl($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function validateUrl($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function validateUrl(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92 1
        return false !== filter_var($value, FILTER_VALIDATE_URL);
93
    }
94
95
    /**
96
     * @param $field
97
     * @param $value
98
     * @param array     $parameters
99
     * @param Validator $validator
100
     *
101
     * @return bool
102
     */
103 1
    public function validateBoolean($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

103
    public function validateBoolean($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

103
    public function validateBoolean(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

103
    public function validateBoolean($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
    {
105 1
        return in_array($value, [true, false, 0, 1, '0', '1'], true);
106
    }
107
108
    /**
109
     * @param $field
110
     * @param $value
111
     * @param array     $parameters
112
     * @param Validator $validator
113
     *
114
     * @return bool
115
     */
116 1
    public function validateConfirm($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

116
    public function validateConfirm(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

116
    public function validateConfirm($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
    {
118 1
        return $value === $this->data[$parameters[0]];
119
    }
120
121
    /**
122
     * @param $field
123
     * @param $value
124
     * @param array     $parameters
125
     * @param Validator $validator
126
     *
127
     * @return bool
128
     */
129 1
    public function validateDate($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

129
    public function validateDate($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

129
    public function validateDate(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

129
    public function validateDate($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
    {
131 1
        return false !== strtotime($value);
132
    }
133
134
    /**
135
     * 邮箱地址
136
     *
137
     * @param $field
138
     * @param $value
139
     * @param array     $parameters
140
     * @param Validator $validator
141
     *
142
     * @return bool
143
     */
144 1
    public function validateEmail($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
    public function validateEmail($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
    public function validateEmail(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
    public function validateEmail($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
145
    {
146 1
        return false !== filter_var($value, FILTER_VALIDATE_EMAIL);
147
    }
148
149
    /**
150
     * @param $field
151
     * @param $value
152
     * @param array     $parameters
153
     * @param Validator $validator
154
     *
155
     * @return bool
156
     */
157 1
    public function validateRequired($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

157
    public function validateRequired($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

157
    public function validateRequired($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

157
    public function validateRequired(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
158
    {
159 1
        return !is_null($value);
160
    }
161
162
    /**
163
     * @param $field
164
     * @param $value
165
     * @param array     $parameters
166
     * @param Validator $validator
167
     *
168
     * @return bool
169
     */
170 1
    public function validateRequiredWith($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

170
    public function validateRequiredWith(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

170
    public function validateRequiredWith($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
    {
172 1
        return !is_null($value) || !array_key_exists($parameters[0], $this->data);
173
    }
174
175
    /**
176
     * @param $field
177
     * @param $value
178
     * @param array     $parameters
179
     * @param Validator $validator
180
     *
181
     * @return bool
182
     */
183 1
    public function validateRequiredWithout($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

183
    public function validateRequiredWithout($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

183
    public function validateRequiredWithout(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184
    {
185 1
        return !is_null($value) || array_key_exists($parameters[0], $this->data);
186
    }
187
188
    /**
189
     * @param $field
190
     * @param $value
191
     * @param array     $parameters
192
     * @param Validator $validator
193
     *
194
     * @return bool
195
     */
196 1
    public function validateRequiredIf($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function validateRequiredIf($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

196
    public function validateRequiredIf(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
197
    {
198 1
        $otherField = array_shift($parameters);
199
200 1
        return !is_null($value) || (
201 1
                !array_key_exists($otherField, $this->data) || false === array_search($this->data[$otherField], $parameters)
202
            );
203
    }
204
205
    /**
206
     * @param $field
207
     * @param $value
208
     * @param array     $parameters
209
     * @param Validator $validator
210
     *
211
     * @return bool
212
     */
213 1
    public function validateRequiredUnless($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

213
    public function validateRequiredUnless($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

213
    public function validateRequiredUnless(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
214
    {
215 1
        $otherField = array_shift($parameters);
216
217 1
        return !is_null($value) || (
218 1
                !array_key_exists($otherField, $this->data) || false !== array_search($this->data[$otherField], $parameters)
219
            );
220
    }
221
222
    /**
223
     * @param $field
224
     * @param $value
225
     * @param array $parameters
226
     *
227
     * @return bool
228
     */
229 1
    public function validateArray($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

229
    public function validateArray($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

229
    public function validateArray($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

229
    public function validateArray(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
230
    {
231 1
        return is_array($value);
232
    }
233
234
    /**
235
     * @param $field
236
     * @param $value
237
     * @param array     $parameters
238
     * @param Validator $validator
239
     *
240
     * @return bool
241
     */
242 1
    public function validateString($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

242
    public function validateString($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

242
    public function validateString($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

242
    public function validateString(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
243
    {
244 1
        return is_string($value);
245
    }
246
247
    /**
248
     * @param $field
249
     * @param $value
250
     * @param array     $parameters
251
     * @param Validator $validator
252
     *
253
     * @return bool
254
     */
255 1
    public function validateNullable($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

255
    public function validateNullable($field, /** @scrutinizer ignore-unused */ $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

255
    public function validateNullable($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

255
    public function validateNullable($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

255
    public function validateNullable(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
256
    {
257 1
        return true;
258
    }
259
260
    /**
261
     * @param $field
262
     * @param $value
263
     * @param array     $parameters
264
     * @param Validator $validator
265
     *
266
     * @return bool
267
     */
268 1
    public function validateMin($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

268
    public function validateMin($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
269
    {
270 1
        return $this->getSize($field, $value) >= $parameters[0];
271
    }
272
273
    /**
274
     * @param $field
275
     * @param $value
276
     * @param array     $parameters
277
     * @param Validator $validator
278
     *
279
     * @return bool
280
     */
281 1
    public function validateMax($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

281
    public function validateMax($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
282
    {
283 1
        return $this->getSize($field, $value) <= $parameters[0];
284
    }
285
286
    /**
287
     * @param $field
288
     * @param $value
289
     * @param array     $parameters
290
     * @param Validator $validator
291
     *
292
     * @return bool
293
     */
294 1
    public function validateRange($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

294
    public function validateRange($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
295
    {
296 1
        $size = $this->getSize($field, $value);
297 1
        if (!isset($parameters[0])) {
298 1
            return false;
299
        }
300 1
        if (isset($parameters[1])) {
301 1
            if ('' === $parameters[0]) {
302 1
                if ('' === $parameters[1]) {
303 1
                    return false;
304
                }
305
306 1
                return $size <= $parameters[1];
307
            }
308 1
            if ('' === $parameters[1]) {
309 1
                return $size >= $parameters[0];
310
            }
311
312 1
            return $size >= $parameters[0] && $size <= $parameters[1];
313
        }
314
315 1
        return '' === $parameters[0] ? false : ($size >= $parameters[0]);
316
    }
317
318
    /**
319
     * @param $field
320
     * @param $value
321
     * @param array     $parameters
322
     * @param Validator $validator
323
     *
324
     * @return bool
325
     */
326 1
    public function validateRegex($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

326
    public function validateRegex(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

326
    public function validateRegex($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
327
    {
328 1
        return (bool) preg_match($parameters[0], $value);
329
    }
330
331
    /**
332
     * @param $field
333
     * @param $value
334
     * @param array     $parameters
335
     * @param Validator $validator
336
     *
337
     * @return bool
338
     */
339 1
    public function validateIn($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

339
    public function validateIn(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

339
    public function validateIn($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
340
    {
341 1
        return in_array($value, $parameters, true);
342
    }
343
344
    /**
345
     * @param $field
346
     * @param $value
347
     * @param array     $parameters
348
     * @param Validator $validator
349
     *
350
     * @return bool
351
     */
352 1
    public function validateIp($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

352
    public function validateIp($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

352
    public function validateIp($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

352
    public function validateIp(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
353
    {
354 1
        return false !== filter_var($value, FILTER_VALIDATE_IP);
355
    }
356
357
    /**
358
     * @param $field
359
     * @param $value
360
     * @param array     $parameters
361
     * @param Validator $validator
362
     *
363
     * @return bool
364
     */
365 1
    public function validateDateFormat($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

365
    public function validateDateFormat(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

365
    public function validateDateFormat($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
366
    {
367 1
        return !(bool) date_parse_from_format($parameters[0], $value)['error_count'];
368
    }
369
370
    /**
371
     * @param $field
372
     * @param $value
373
     * @param array     $parameters
374
     * @param Validator $validator
375
     *
376
     * @return bool
377
     */
378 1
    public function validateDateBefore($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

378
    public function validateDateBefore($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

378
    public function validateDateBefore(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
379
    {
380 1
        return strtotime($value) < strtotime($parameters[0]);
381
    }
382
383
    /**
384
     * @param $field
385
     * @param $value
386
     * @param array     $parameters
387
     * @param Validator $validator
388
     *
389
     * @return bool
390
     */
391 1
    public function validateDateAfter($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

391
    public function validateDateAfter(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

391
    public function validateDateAfter($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
392
    {
393 1
        return strtotime($value) > strtotime($parameters[0]);
394
    }
395
396
    /**
397
     * @param $field
398
     * @param $value
399
     * @param array     $parameters
400
     * @param Validator $validator
401
     *
402
     * @return bool
403
     */
404 1
    public function validateJson($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

404
    public function validateJson($field, $value, /** @scrutinizer ignore-unused */ array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

404
    public function validateJson(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

404
    public function validateJson($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
405
    {
406 1
        return is_array(json_decode($value, true));
407
    }
408
409
    /**
410
     * @param $field
411
     * @param $value
412
     * @param array     $parameters
413
     * @param Validator $validator
414
     *
415
     * @return bool
416
     */
417 1
    public function validateDiff($field, $value, array $parameters, Validator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

417
    public function validateDiff(/** @scrutinizer ignore-unused */ $field, $value, array $parameters, Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

417
    public function validateDiff($field, $value, array $parameters, /** @scrutinizer ignore-unused */ Validator $validator)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
418
    {
419 1
        $specifyField = array_shift($parameters);
420
421 1
        return array_key_exists($specifyField, $this->data) && $value !== $this->data[$specifyField];
422
    }
423
424
    /**
425
     * @param $field
426
     * @param $value
427
     *
428
     * @return int|float
429
     */
430 2
    public function getSize($field, $value)
431
    {
432
        switch (true) {
433 2
            case isset($this->ruleGroups[$field]['String']) && is_string($value):
434 1
                return strlen($value);
435 2
            case is_array($value):
436 1
                return count($value);
437 2
            case false !== $temp = filter_var($value, FILTER_VALIDATE_INT):
438 1
                return $temp;
439 2
            case false !== $temp = filter_var($value, FILTER_VALIDATE_FLOAT):
440 1
                return $temp;
441
            default:
442 2
                return mb_strlen($value);
443
        }
444
    }
445
}
446