Code Duplication    Length = 19-19 lines in 4 locations

src/Constraint/DraftFour/MaxItems.php 1 location

@@ 10-28 (lines=19) @@
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
final class MaxItems implements ConstraintInterface
11
{
12
    const KEYWORD = 'maxItems';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($value, $parameter, Validator $validator)
18
    {
19
        Assert::type($parameter, 'integer', self::KEYWORD, $validator->getSchemaPath());
20
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22
        if (!is_array($value) || count($value) <= $parameter) {
23
            return null;
24
        }
25
26
        return error('The array must contain less than {parameter} items.', $validator);
27
    }
28
}
29

src/Constraint/DraftFour/MaxProperties.php 1 location

@@ 10-28 (lines=19) @@
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
final class MaxProperties implements ConstraintInterface
11
{
12
    const KEYWORD = 'maxProperties';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($value, $parameter, Validator $validator)
18
    {
19
        Assert::type($parameter, 'integer', self::KEYWORD, $validator->getSchemaPath());
20
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22
        if (!is_object($value) || count(get_object_vars($value)) <= $parameter) {
23
            return null;
24
        }
25
26
        return error('The object must contain less than {parameter} properties.', $validator);
27
    }
28
}
29

src/Constraint/DraftFour/MinItems.php 1 location

@@ 10-28 (lines=19) @@
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
final class MinItems implements ConstraintInterface
11
{
12
    const KEYWORD = 'minItems';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($value, $parameter, Validator $validator)
18
    {
19
        Assert::type($parameter, 'integer', self::KEYWORD, $validator->getSchemaPath());
20
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22
        if (!is_array($value) || count($value) >= $parameter) {
23
            return null;
24
        }
25
26
        return error('The array must contain at least {parameter} items.', $validator);
27
    }
28
}
29

src/Constraint/DraftFour/MinProperties.php 1 location

@@ 10-28 (lines=19) @@
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
final class MinProperties implements ConstraintInterface
11
{
12
    const KEYWORD = 'minProperties';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($value, $parameter, Validator $validator)
18
    {
19
        Assert::type($parameter, 'integer', self::KEYWORD, $validator->getSchemaPath());
20
        Assert::nonNegative($parameter, self::KEYWORD, $validator->getSchemaPath());
21
22
        if (!is_object($value) || count(get_object_vars($value)) >= $parameter) {
23
            return null;
24
        }
25
26
        return error('The object must contain at least {parameter} properties.', $validator);
27
    }
28
}
29