AnyOf   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 42.31 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 11
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 11 18 3

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\Assert;
6
use League\JsonGuard\ConstraintInterface;
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
use function League\JsonGuard\pointer_push;
10
11
final class AnyOf implements ConstraintInterface
12
{
13
    const KEYWORD = 'anyOf';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 6
    public function validate($value, $parameter, Validator $validator)
19
    {
20 6
        Assert::type($parameter, 'array', self::KEYWORD, $validator->getSchemaPath());
21 4
        Assert::notEmpty($parameter, self::KEYWORD, $validator->getSchemaPath());
22
23 4 View Code Duplication
        foreach ($parameter as $key => $schema) {
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...
24 4
            $subValidator = $validator->makeSubSchemaValidator(
25 4
                $value,
26 4
                $schema,
27 4
                $validator->getDataPath(),
28 4
                pointer_push($validator->getSchemaPath(), $key)
29
            );
30 4
            if ($subValidator->passes()) {
31 4
                return null;
32
            }
33
        }
34 4
        return error('The data must match one of the schemas.', $validator);
35
    }
36
}
37