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

Method demo

examples/demo.php:644–666  ·  view source on GitHub ↗

@param list $pens */

(array $pens)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

getUnknownValueFunction · 0.85
colorMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected