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 League\JsonGuard\Constraints; |
||
4 | |||
5 | use League\JsonGuard; |
||
6 | use League\JsonGuard\ErrorCode; |
||
7 | use League\JsonGuard\ValidationError; |
||
8 | |||
9 | View Code Duplication | class MaxItems implements PropertyConstraint |
|
0 ignored issues
–
show
|
|||
10 | { |
||
11 | /** |
||
12 | * {@inheritdoc} |
||
13 | */ |
||
14 | 8 | public static function validate($value, $parameter, $pointer = null) |
|
15 | { |
||
16 | 8 | if (!is_array($value) || count($value) <= $parameter) { |
|
17 | 8 | return null; |
|
18 | } |
||
19 | |||
20 | 8 | $message = sprintf('Array does not contain less than "%d" items', JsonGuard\as_string($parameter)); |
|
21 | 8 | return new ValidationError( |
|
22 | 8 | $message, |
|
23 | 8 | ErrorCode::MAX_ITEMS_EXCEEDED, |
|
24 | 8 | $value, |
|
25 | 8 | $pointer, |
|
26 | 8 | ['max_items' => $parameter] |
|
27 | 8 | ); |
|
28 | } |
||
29 | } |
||
30 |
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.