AllOfConstraint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A keywords() 0 4 1
A apply() 12 12 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
/*
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