PatternProperties   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 9
loc 31
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 9 23 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard;
6
use League\JsonGuard\Assert;
7
use League\JsonGuard\ConstraintInterface;
8
use League\JsonGuard\Validator;
9
use function League\JsonGuard\pointer_push;
10
11
final class PatternProperties implements ConstraintInterface
12
{
13
    const KEYWORD = 'patternProperties';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 8
    public function validate($value, $parameter, Validator $validator)
19
    {
20 8
        Assert::type($parameter, 'object', self::KEYWORD, $validator->getSchemaPath());
21
22 6
        if (!is_object($value)) {
23 4
            return null;
24
        }
25
26 6
        $errors = [];
27 6
        foreach ($parameter as $property => $schema) {
28 6
            $matches = JsonGuard\properties_matching_pattern($property, $value);
29 6 View Code Duplication
            foreach ($matches as $match) {
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...
30 6
                $subValidator = $validator->makeSubSchemaValidator(
31 6
                    $value->$match,
32 6
                    $schema,
33 6
                    pointer_push($validator->getDataPath(), $match),
34 6
                    pointer_push($validator->getSchemaPath(), $property)
35
                );
36 6
                $errors = array_merge($errors, $subValidator->errors());
37
            }
38
        }
39 6
        return $errors;
40
    }
41
}
42