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