()
| 324 | class 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 |
nothing calls this directly
no test coverage detected