@param list $pens */
(array $pens)
| 642 | { |
| 643 | /** @param list<Pen> $pens */ |
| 644 | public function demo(array $pens): void |
| 645 | { |
| 646 | // Pattern 1: null-init + foreach reassignment + truthiness guard |
| 647 | $found = null; |
| 648 | foreach ($pens as $pen) { |
| 649 | if ($pen->color() === 'blue') { |
| 650 | $found = $pen; |
| 651 | } |
| 652 | } |
| 653 | if ($found) { |
| 654 | $found->write(); // Pen from foreach reassignment |
| 655 | } |
| 656 | |
| 657 | // Pattern 2: null-coalesce + guard inside foreach |
| 658 | /** @var array<string, Pen> $lookup */ |
| 659 | $lookup = getUnknownValue(); |
| 660 | $keys = ['a', 'b']; |
| 661 | foreach ($keys as $key) { |
| 662 | $item = $lookup[$key] ?? null; |
| 663 | if (!$item) { continue; } |
| 664 | $item->write(); // Pen from array access via coalesce |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 |
nothing calls this directly
no test coverage detected