AllOf::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 9
Ratio 47.37 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 3
dl 9
loc 19
ccs 12
cts 12
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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\pointer_push;
9
10
final class AllOf implements ConstraintInterface
11
{
12
    const KEYWORD = 'allOf';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 8
    public function validate($value, $parameter, Validator $validator)
18
    {
19 8
        Assert::type($parameter, 'array', self::KEYWORD, $validator->getSchemaPath());
20 4
        Assert::notEmpty($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22 4
        $errors = [];
23
24 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...
25 4
            $subValidator = $validator->makeSubSchemaValidator(
26 4
                $value,
27 4
                $schema,
28 4
                $validator->getDataPath(),
29 4
                pointer_push($validator->getSchemaPath(), $key)
30
            );
31 4
            $errors = array_merge($errors, $subValidator->errors());
32
        }
33
34 4
        return $errors;
35
    }
36
}
37