()
| 1651 | class GeneratorDemo |
| 1652 | { |
| 1653 | public function demo(): void |
| 1654 | { |
| 1655 | // Generator<int, Pen> — value is 2nd param (Pen) |
| 1656 | foreach ($this->getPens() as $pen) { |
| 1657 | $pen->write(); // resolves to Pen |
| 1658 | } |
| 1659 | |
| 1660 | // Generator<int, Pencil, mixed, Pen> — value is still 2nd param (Pencil) |
| 1661 | foreach ($this->processPencils() as $pencil) { |
| 1662 | $pencil->sketch(); // Pencil (2nd param), not Pen (4th) |
| 1663 | } |
| 1664 | |
| 1665 | // @var annotated generator |
| 1666 | /** @var \Generator<int, Pen> $gen */ |
| 1667 | $gen = $this->getPens(); |
| 1668 | foreach ($gen as $pen) { |
| 1669 | $pen->write(); // Generator<int, Pen> → Pen |
| 1670 | } |
| 1671 | |
| 1672 | // iterable<Pen> — single param is the value type |
| 1673 | foreach ($this->iterablePens() as $pen) { |
| 1674 | $pen->write(); |
| 1675 | } |
| 1676 | |
| 1677 | // Method chain through generator element |
| 1678 | foreach ($this->getPens() as $pen) { |
| 1679 | $pen->rename('Bold')->color(); |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /** @return \Generator<int, Pen> */ |
| 1684 | public function getPens(): \Generator |
nothing calls this directly
no test coverage detected