Completed
Push — master ( e98ae3...0e888f )
by Matt
02:50
created

AnyOf::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 6
Ratio 31.58 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 4
dl 6
loc 19
ccs 15
cts 15
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Constraints;
4
5
use League\JsonGuard\Assert;
6
use League\JsonGuard\SubSchemaValidatorFactory;
7
use League\JsonGuard\ValidationError;
8
9
class AnyOf implements ContainerInstanceConstraint
10
{
11
    const KEYWORD = 'anyOf';
12
13
    /**
14
     * {@inheritdoc}
15
     */
16 10
    public static function validate($data, $parameter, SubSchemaValidatorFactory $validatorFactory, $pointer = null)
17
    {
18 10
        Assert::type($parameter, 'array', self::KEYWORD, $pointer);
19 8
        Assert::notEmpty($parameter, self::KEYWORD, $pointer);
20
21 8 View Code Duplication
        foreach ($parameter as $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...
22 8
            $validator = $validatorFactory->makeSubSchemaValidator($data, $schema, $pointer);
23 8
            if ($validator->passes()) {
24 8
                return null;
25
            }
26 8
        }
27 8
        return new ValidationError(
28 8
            'Failed matching any of the provided schemas.',
29 8
            self::KEYWORD,
30 8
            $data,
31 8
            $pointer,
32 8
            ['any_of' => $parameter]
33 8
        );
34
    }
35
}
36