AllOfConstraint::apply()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 4
nop 4
crap 3
1
<?php
2
3
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal\Constraint;
11
12
use JVal\Context;
13
use JVal\Walker;
14
use stdClass;
15
16
/**
17
 * Constraint for the "allOf" keyword.
18
 */
19
class AllOfConstraint extends AbstractOfConstraint
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 377
    public function keywords()
25
    {
26 377
        return ['allOf'];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 22 View Code Duplication
    public function apply($instance, stdClass $schema, Context $context, Walker $walker)
33
    {
34 22
        $originalCount = $context->countViolations();
35
36 22
        foreach ($schema->allOf as $subSchema) {
37 22
            $walker->applyConstraints($instance, $subSchema, $context);
38 22
        }
39
40 22
        if ($context->countViolations() > $originalCount) {
41 12
            $context->addViolation('instance must match all the schemas listed in allOf');
42 12
        }
43 22
    }
44
}
45