UniqueItems   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 4
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
final class UniqueItems implements ConstraintInterface
11
{
12
    const KEYWORD = 'uniqueItems';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 8
    public function validate($value, $parameter, Validator $validator)
18
    {
19 8
        Assert::type($parameter, 'boolean', self::KEYWORD, $validator->getSchemaPath());
20
21 6
        if (!is_array($value) || $parameter === false) {
22 2
            return null;
23
        }
24
25 4
        if (count($value) === count(array_unique(array_map('serialize', $value)))) {
26 4
            return null;
27
        }
28
29 2
        return error('The array must be unique.', $validator);
30
    }
31
}
32