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

Method demo

examples/demo.php:354–371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

352class GuardClauseDemo
353{
354 public function demo(): void
355 {
356 $subject = pickRockOrBanana(); // Rock|Banana
357 if (!$subject instanceof Banana) {
358 return; // early return — guard clause
359 }
360 $subject->peel(); // narrowed to Banana after guard
361
362 $candidate = pickRockOrBanana(); // Rock|Banana
363 if ($candidate instanceof Rock) {
364 throw new Exception('no rocks'); // early throw — guard clause
365 }
366 $candidate->peel(); // narrowed to Banana (Rock excluded)
367
368 $unknown = getUnknownValue();
369 if (!$unknown instanceof Rock) return; // single-statement guard (no braces)
370 $unknown->crush(); // narrowed to Rock
371 }
372
373 /** Positive instanceof + early return on a mixed parameter. */
374 public function mixedGuard(mixed $value): void

Callers

nothing calls this directly

Calls 4

pickRockOrBananaFunction · 0.85
getUnknownValueFunction · 0.85
peelMethod · 0.80
crushMethod · 0.80

Tested by

no test coverage detected