Commit a349947
committed
Tokenizer/PHP:
When support for the `goto` construct was introduced, it was elected to tokenize the "goto target label" as a separate `T_GOTO_LABEL` token, including the colon following it.
This is wrong as PHP does not enforce for the colon to be the next token and allows whitespace and comments between the goto label and the colon. In which case, the tokenization in PHPCS would be incorrect as the label would stay a `T_STRING` instead of becoming `T_GOTO_LABEL`.
This commit fixes this.
It also introduces a new `T_GOTO_COLON` token and re-tokenizes the colon (separate from the label) to `T_GOTO_COLON`.
This choice was made so as not to confuse the Tokenizer (nor sniffs) with yet another usage for `T_COLON`, which is an ambiguous enough token as it is (alternative control structures, switch - case statements, return type statements, enum types, ternaries etc).
This change is covered by the existing (updated) tests.
Includes one minor update to a sniff to allow for this change.
Refs:
* https://www.php.net/manual/en/control-structures.goto.php
* https://3v4l.org/ccbVD
Fixes squizlabs/PHP_CodeSniffer 3161
Fixes 185T_GOTO_LABEL no longer contains colon1 parent a78b0dd commit a349947
File tree
5 files changed
+70
-37
lines changed- src
- Standards/Squiz/Sniffs/PHP
- Tokenizers
- Util
- tests/Core/Tokenizers/PHP
5 files changed
+70
-37
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
| |||
2199 | 2200 | | |
2200 | 2201 | | |
2201 | 2202 | | |
2202 | | - | |
2203 | | - | |
2204 | 2203 | | |
2205 | 2204 | | |
2206 | 2205 | | |
2207 | | - | |
2208 | | - | |
2209 | | - | |
2210 | | - | |
2211 | | - | |
2212 | | - | |
2213 | | - | |
2214 | | - | |
2215 | | - | |
2216 | | - | |
2217 | | - | |
2218 | | - | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
2219 | 2212 | | |
| 2213 | + | |
| 2214 | + | |
2220 | 2215 | | |
2221 | 2216 | | |
2222 | | - | |
2223 | | - | |
2224 | | - | |
2225 | | - | |
2226 | | - | |
2227 | | - | |
2228 | | - | |
2229 | | - | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
2230 | 2227 | | |
2231 | 2228 | | |
2232 | | - | |
2233 | | - | |
2234 | | - | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
2235 | 2233 | | |
2236 | 2234 | | |
2237 | | - | |
2238 | | - | |
2239 | | - | |
2240 | | - | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
2241 | 2264 | | |
2242 | 2265 | | |
2243 | 2266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | | - | |
| 78 | + | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
95 | 104 | | |
96 | 105 | | |
97 | 106 | | |
| |||
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
110 | | - | |
| 119 | + | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
114 | | - | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
118 | | - | |
| 127 | + | |
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
122 | | - | |
| 131 | + | |
123 | 132 | | |
124 | 133 | | |
125 | 134 | | |
| |||
0 commit comments