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 |
||
22 | 23 | public function pass(Expr\Array_ $expr, Context $context) |
|
23 | { |
||
24 | 23 | $result = false; |
|
25 | 23 | $keys = []; |
|
26 | |||
27 | /** @var Expr\ArrayItem $item */ |
||
28 | 23 | foreach ($expr->items as $item) { |
|
29 | 9 | $compiledKey = $context->getExpressionCompiler()->compile($item->key); |
|
30 | 9 | if (!$compiledKey->isTypeKnown() || !$compiledKey->isScalar() || !$compiledKey->hasValue()) { |
|
31 | 7 | continue; |
|
32 | } |
||
33 | |||
34 | 2 | $key = $compiledKey->getValue(); |
|
35 | |||
36 | 2 | if (isset($keys[$key])) { |
|
37 | 1 | $context->notice( |
|
38 | 1 | 'array.duplicate_keys', |
|
39 | 1 | sprintf( |
|
40 | 1 | 'Duplicate array key "%s" in array definition (previously declared in line %d).', |
|
41 | 1 | $item->key instanceof Expr\Variable ? sprintf('$%s (resolved value: "%s")', $item->key->name, $key) : $key, |
|
42 | 1 | $keys[$key]->getLine() |
|
43 | 1 | ), |
|
44 | $item |
||
45 | 1 | ); |
|
46 | |||
47 | 1 | $result = true; |
|
48 | 1 | } |
|
49 | |||
50 | 2 | $keys[$key] = $item; |
|
51 | 23 | } |
|
52 | |||
53 | 23 | return $result; |
|
54 | } |
||
55 | |||
66 |