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

Method demo

examples/demo.php:1332–1358  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1330class DestructuringShapeDemo
1331{
1332 public function demo(): void
1333 {
1334 // Named key from method return
1335 ['pen' => $pen, 'pencil' => $pencil] = $this->getToolKit();
1336 $pen->write(); // Pen from 'pen' key
1337 $pencil->sketch(); // Pencil from 'pencil' key
1338
1339 // Named key from @var annotated variable
1340 /** @var array{pen: Pen, pencil: Pencil, active: bool} $data */
1341 $data = getUnknownValue();
1342 ['pen' => $myPen, 'pencil' => $myPencil] = $data;
1343 $myPen->write(); // Pen from 'pen' key
1344 $myPencil->sketch(); // Pencil from 'pencil' key
1345
1346 // Positional from shape
1347 /** @var array{Pen, Pencil} $pair */
1348 $pair = getUnknownValue();
1349 [$first, $second] = $pair;
1350 $first->write(); // Pen (positional index 0)
1351 $second->sketch(); // Pencil (positional index 1)
1352
1353 // list() syntax
1354 /** @var array{recipe: Recipe, servings: int} $meal */
1355 $meal = getUnknownValue();
1356 list('recipe' => $recipe) = $meal;
1357 $recipe->ingredients; // Recipe from 'recipe' key
1358 }
1359
1360 /** @return array{pen: Pen, pencil: Pencil, count: int} */
1361 public function getToolKit(): array { return []; }

Callers

nothing calls this directly

Calls 4

getToolKitMethod · 0.95
getUnknownValueFunction · 0.85
writeMethod · 0.80
sketchMethod · 0.80

Tested by

no test coverage detected