Code Duplication    Length = 8-11 lines in 6 locations

src/Constraint/DraftFour/AdditionalItems.php 1 location

@@ 59-66 (lines=8) @@
56
    private static function validateAdditionalItemsAgainstSchema($items, $schema, Validator $validator)
57
    {
58
        $errors = [];
59
        foreach ($items as $key => $item) {
60
            $subValidator = $validator->makeSubSchemaValidator(
61
                $item,
62
                $schema,
63
                pointer_push($validator->getDataPath(), $key)
64
            );
65
            $errors = array_merge($errors, $subValidator->errors());
66
        }
67
68
        return $errors;
69
    }

src/Constraint/DraftFour/AdditionalProperties.php 1 location

@@ 40-47 (lines=8) @@
37
            // If additionalProperties is an object it's a schema,
38
            // so validate all additional properties against it.
39
            $errors = [];
40
            foreach ($diff as $property) {
41
                $subValidator = $validator->makeSubSchemaValidator(
42
                    $value->$property,
43
                    $parameter,
44
                    pointer_push($validator->getDataPath(), $property)
45
                );
46
                $errors = array_merge($errors, $subValidator->errors());
47
            }
48
49
            return $errors;
50
        }

src/Constraint/DraftFour/AllOf.php 1 location

@@ 24-32 (lines=9) @@
21
22
        $errors = [];
23
24
        foreach ($parameter as $key => $schema) {
25
            $subValidator = $validator->makeSubSchemaValidator(
26
                $value,
27
                $schema,
28
                $validator->getDataPath(),
29
                pointer_push($validator->getSchemaPath(), $key)
30
            );
31
            $errors = array_merge($errors, $subValidator->errors());
32
        }
33
34
        return $errors;
35
    }

src/Constraint/DraftFour/AnyOf.php 1 location

@@ 23-33 (lines=11) @@
20
        Assert::type($parameter, 'array', self::KEYWORD, $validator->getSchemaPath());
21
        Assert::notEmpty($parameter, self::KEYWORD, $validator->getSchemaPath());
22
23
        foreach ($parameter as $key => $schema) {
24
            $subValidator = $validator->makeSubSchemaValidator(
25
                $value,
26
                $schema,
27
                $validator->getDataPath(),
28
                pointer_push($validator->getSchemaPath(), $key)
29
            );
30
            if ($subValidator->passes()) {
31
                return null;
32
            }
33
        }
34
        return error('The data must match one of the schemas.', $validator);
35
    }
36
}

src/Constraint/DraftFour/OneOf.php 1 location

@@ 24-34 (lines=11) @@
21
        Assert::notEmpty($parameter, self::KEYWORD, $validator->getSchemaPath());
22
23
        $passed = 0;
24
        foreach ($parameter as $key => $schema) {
25
            $subValidator = $validator->makeSubSchemaValidator(
26
                $value,
27
                $schema,
28
                $validator->getDataPath(),
29
                pointer_push($validator->getSchemaPath(), $key)
30
            );
31
            if ($subValidator->passes()) {
32
                $passed++;
33
            }
34
        }
35
        if ($passed !== 1) {
36
            return error('The data must match exactly one of the schemas.', $validator);
37
        }

src/Constraint/DraftFour/PatternProperties.php 1 location

@@ 29-37 (lines=9) @@
26
        $errors = [];
27
        foreach ($parameter as $property => $schema) {
28
            $matches = JsonGuard\properties_matching_pattern($property, $value);
29
            foreach ($matches as $match) {
30
                $subValidator = $validator->makeSubSchemaValidator(
31
                    $value->$match,
32
                    $schema,
33
                    pointer_push($validator->getDataPath(), $match),
34
                    pointer_push($validator->getSchemaPath(), $property)
35
                );
36
                $errors = array_merge($errors, $subValidator->errors());
37
            }
38
        }
39
        return $errors;
40
    }