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

Method demo

examples/demo.php:326–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

324class StaticAssertNarrowingDemo
325{
326 public function demo(): void
327 {
328 // @phpstan-assert on static method — unconditional narrowing
329 $unknown = getUnknownValue();
330 StaticAssert::assertRock($unknown);
331 $unknown->crush(); // narrowed to Rock
332
333 // @phpstan-assert-if-true on static method — narrows in then-branch
334 $sample = pickRockOrBanana();
335 if (StaticAssert::isRock($sample)) {
336 $sample->crush(); // narrowed to Rock
337 }
338
339 // @phpstan-assert-if-false on static method — narrows in else-branch
340 $maybe = pickRockOrBanana();
341 if (StaticAssert::isNotRock($maybe)) {
342 $maybe->peel(); // narrowed to Banana
343 } else {
344 $maybe->crush(); // narrowed to Rock
345 }
346 }
347}
348
349

Callers

nothing calls this directly

Calls 7

getUnknownValueFunction · 0.85
pickRockOrBananaFunction · 0.85
assertRockMethod · 0.80
crushMethod · 0.80
isRockMethod · 0.80
isNotRockMethod · 0.80
peelMethod · 0.80

Tested by

no test coverage detected