Completed
Push — master ( 687421...d46160 )
by Viacheslav
9s
created

UniqueItems   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 27
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 0 20 7
1
<?php
2
3
namespace Swaggest\JsonSchema\Constraint;
4
5
use Swaggest\JsonSchema\Structure\ObjectItemContract;
6
7
class UniqueItems
8
{
9
    /**
10
     * @param array $data
11
     * @return bool
12
     * @todo optimize a lot
13
     */
14 499
    public static function isValid(array $data)
15
    {
16 499
        $index = array();
17 499
        foreach ($data as $value) {
18 481
            if (is_array($value) || $value instanceof \stdClass) {
19 43
                $value = json_encode($value);
20
            }
21 481
            if (is_bool($value)) {
22 33
                $value = '_______BOOL' . $value;
23
            }
24 481
            if ($value instanceof ObjectItemContract) {
25 1
                $value = json_encode($value);
26
            }
27 481
            $tmp = &$index[$value];
28 481
            if ($tmp !== null) {
29 19
                return false;
30
            }
31 481
            $tmp = true;
32
        }
33 480
        return true;
34
    }
35
36
}