MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / demo

Method demo

examples/demo.php:1653–1681  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1651class 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

Callers

nothing calls this directly

Calls 7

getPensMethod · 0.95
processPencilsMethod · 0.95
iterablePensMethod · 0.95
writeMethod · 0.80
sketchMethod · 0.80
colorMethod · 0.80
renameMethod · 0.45

Tested by

no test coverage detected