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