Commit 5857b59
Add comment explaining Variable exception and add variable-equivalent test cases
Address review comment by VincentLanglet asking why the guard is restricted
to non-Variable expressions.
The Variable exception is needed because:
- Non-Variable expressions (array dim fetches, property fetches) are always
queryable; absence from a branch means "not narrowed", not "doesn't exist"
- Variables are different: absence means genuinely "not defined", and
conditional expressions for newly-defined variables are essential for
variable certainty tracking (e.g. bug-14411-regression where $order must
be recognised as always-defined when two conditions cover all cases)
- Pre-defined variables (present in both branches) are already handled by
the existing check that tests array_key_exists($exprString, $theirExpressionTypes)
Added variable-equivalent test cases to both the rule test data and NSRT
test to demonstrate that pre-defined variables work correctly with the
existing guard-overlap check.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 32c94b9 commit 5857b59
3 files changed
Lines changed: 52 additions & 0 deletions
File tree
- src/Analyser
- tests/PHPStan
- Analyser/nsrt
- Rules/Comparison/data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3649 | 3649 | | |
3650 | 3650 | | |
3651 | 3651 | | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
| 3658 | + | |
| 3659 | + | |
| 3660 | + | |
| 3661 | + | |
| 3662 | + | |
| 3663 | + | |
3652 | 3664 | | |
3653 | 3665 | | |
3654 | 3666 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
0 commit comments