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

MinProperties::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 3
Metric Value
cc 3
eloc 10
nc 2
nop 3
dl 15
loc 15
ccs 11
cts 11
cp 1
crap 3
rs 9.4285
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