MinPropertiesConstraint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A keywords() 4 4 1
A supports() 4 4 1
A apply() 9 9 2

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\Types;
14
use JVal\Walker;
15
use stdClass;
16
17
/**
18
 * Constraint for the "minProperties" keyword.
19
 */
20 View Code Duplication
class MinPropertiesConstraint extends AbstractCountConstraint
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 378
    public function keywords()
26
    {
27 378
        return ['minProperties'];
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 357
    public function supports($type)
34
    {
35 357
        return $type === Types::TYPE_OBJECT;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 6
    public function apply($instance, stdClass $schema, Context $context, Walker $walker)
42
    {
43 6
        if (count(get_object_vars($instance)) < $schema->minProperties) {
44 2
            $context->addViolation(
45 2
                'number of properties should be greater than or equal to %s',
46 2
                [$schema->minProperties]
47 2
            );
48 2
        }
49 6
    }
50
}
51