* @param Rock|Banana $item * @param list $rocks */
($item, array $rocks)
| 393 | * @param list<Rock> $rocks |
| 394 | */ |
| 395 | public function demo($item, array $rocks): void |
| 396 | { |
| 397 | if (in_array($item, $rocks, true)) { |
| 398 | $item->crush(); // narrowed to Rock |
| 399 | // MUST NOT appear: peel() (Banana only) |
| 400 | } else { |
| 401 | $item->peel(); // excluded Rock → Banana |
| 402 | // MUST NOT appear: crush() (Rock only) |
| 403 | } |
| 404 | |
| 405 | // Guard clause with in_array |
| 406 | $specimen = pickRockOrBanana(); // Rock|Banana |
| 407 | if (!in_array($specimen, $rocks, true)) { |
| 408 | return; |
| 409 | } |
| 410 | $specimen->crush(); // narrowed to Rock after guard |
| 411 | } |
| 412 | } |
| 413 | |
| 414 |
nothing calls this directly
no test coverage detected