Completed
Push — master ( 5927eb...1e13db )
by
unknown
04:04
created

MinProperties   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
dl 21
loc 21
ccs 11
cts 11
cp 1
rs 10
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 15 15 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
namespace League\JsonGuard\Constraints;
4
5
use League\JsonGuard;
6
use League\JsonGuard\ErrorCode;
7
use League\JsonGuard\ValidationError;
8
9 View Code Duplication
class MinProperties implements PropertyConstraint
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 2
    public static function validate($value, $min, $pointer = null)
15
    {
16 2
        if (!is_object($value) || count(get_object_vars($value)) >= $min) {
17 2
            return null;
18
        }
19
20 2
        $message = sprintf('Object does not contain at least "%d" properties', JsonGuard\asString($min));
21 2
        return new ValidationError(
22 2
            $message,
23 2
            ErrorCode::INVALID_MIN_COUNT,
24 2
            $value,
25 2
            $pointer,
26 2
            ['min_properties' => $min]
27 2
        );
28
    }
29
}
30