MaxProperties::validate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 3
dl 11
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard\Assert;
6
use League\JsonGuard\ConstraintInterface;
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10 View Code Duplication
final class MaxProperties implements ConstraintInterface
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...
11
{
12
    const KEYWORD = 'maxProperties';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 6
    public function validate($value, $parameter, Validator $validator)
18
    {
19 6
        Assert::type($parameter, 'integer', self::KEYWORD, $validator->getSchemaPath());
20 4
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22 2
        if (!is_object($value) || count(get_object_vars($value)) <= $parameter) {
23 2
            return null;
24
        }
25
26 2
        return error('The object must contain less than {parameter} properties.', $validator);
27
    }
28
}
29