Commit 0c1f4d5
committed
Tokenizer/PHP: fix handling of "DNF look a likes" with switch/case and alternative control structure syntax
Follow up on 461, 507, 508
This commit intends to further improve the determination of whether tokens are part of a (return) type declaration which need special handling for the tokens or not.
It does more strenuous checking on any `T_COLON` encountered before the (potential) type, to try and determine with higher accuracy whether the colon indicates the start of a return type - in contrast to being a colon for a switch-case or a colon for an alternative syntax control structure.
Includes tests.
The tests also include a test with `goto`. This would currently not trigger this code as the colon is tokenized as part of the goto label, but as the intention is to change that tokenization in PHPCS 4.0 (per issue 185), the test being there should safeguard that the PHPCS 4.0 change will not cause any problems with the DNF related tokenization.
For now, this fixes the bug(s) reported in issue 630, though I think it might be good to revisit the tokenizer control flow in a future major, but as that will be so much easier once JS/CSS no longer needs to be taken into account, that's for the future.
Fixes 6301 parent 9e60f9f commit 0c1f4d5
File tree
3 files changed
+92
-4
lines changed- src/Tokenizers
- tests/Core/Tokenizer/PHP
3 files changed
+92
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3226 | 3226 | | |
3227 | 3227 | | |
3228 | 3228 | | |
3229 | | - | |
| 3229 | + | |
3230 | 3230 | | |
3231 | 3231 | | |
3232 | 3232 | | |
3233 | 3233 | | |
3234 | 3234 | | |
3235 | 3235 | | |
3236 | | - | |
3237 | | - | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
3238 | 3264 | | |
3239 | 3265 | | |
3240 | 3266 | | |
3241 | | - | |
| 3267 | + | |
3242 | 3268 | | |
3243 | 3269 | | |
3244 | 3270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
56 | 85 | | |
57 | 86 | | |
58 | 87 | | |
| |||
165 | 194 | | |
166 | 195 | | |
167 | 196 | | |
| 197 | + | |
| 198 | + | |
168 | 199 | | |
169 | 200 | | |
170 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
196 | 223 | | |
197 | 224 | | |
198 | 225 | | |
| |||
423 | 450 | | |
424 | 451 | | |
425 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
426 | 457 | | |
427 | 458 | | |
428 | 459 | | |
| |||
0 commit comments