Commit 5893446
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 16b3cca commit 5893446
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 | |
|---|---|---|---|
| |||
3780 | 3780 | | |
3781 | 3781 | | |
3782 | 3782 | | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
3783 | 3795 | | |
3784 | 3796 | | |
3785 | 3797 | | |
| |||
| 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