Conditions | 7 |
Paths | 4 |
Total Lines | 33 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 7 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | 26 | public function pass(Expr\Array_ $expr, Context $context) |
|
29 | { |
||
30 | 26 | $result = false; |
|
31 | 26 | $keys = []; |
|
32 | |||
33 | /** @var Expr\ArrayItem $item */ |
||
34 | 26 | foreach ($expr->items as $item) { |
|
35 | 10 | $compiledKey = $context->getExpressionCompiler()->compile($item->key); |
|
36 | 10 | if (!$compiledKey->isTypeKnown() || !$compiledKey->isScalar() || !$compiledKey->hasValue()) { |
|
37 | 8 | continue; |
|
38 | } |
||
39 | |||
40 | 3 | $key = $compiledKey->getValue(); |
|
41 | |||
42 | 3 | if (isset($keys[$key])) { |
|
43 | 1 | $context->notice( |
|
44 | 1 | 'array.duplicate_keys', |
|
45 | 1 | sprintf( |
|
46 | 1 | 'Duplicate array key "%s" in array definition (previously declared in line %d).', |
|
47 | 1 | $item->key instanceof Expr\Variable ? sprintf('$%s (resolved value: "%s")', $item->key->name, $key) : $key, |
|
48 | 1 | $keys[$key]->getLine() |
|
49 | 1 | ), |
|
50 | $item |
||
51 | 1 | ); |
|
52 | |||
53 | 1 | $result = true; |
|
54 | 1 | } |
|
55 | |||
56 | 3 | $keys[$key] = $item; |
|
57 | 26 | } |
|
58 | |||
59 | 26 | return $result; |
|
60 | } |
||
61 | |||
72 |