Commit 4444dc9
committed
UseStatements::splitImportUseStatement(): compatibility with the PHP 8 identifier name tokenization
As the PHP 8 identifier name tokens will not always exist in all supported PHP/PHPCS versions, the token code comparison needs to be switched to a token type comparison to prevent "unknown constant" errors.
Additionally, the `UseStatements::splitImportUseStatement()` method uses the last part of an imported name as the alias/array index key if no alias is given.
For the PHP 5/7 tokenization, this was handled by overwriting the`$alias` while the method was still going through the various parts of the name until it found the end.
For the PHP 8 tokenization, however, the various parts of the name are now all squashed together into one token, so we need to extract the last part of the name from the (fully) qualified name to get to the "alias".
As an extra issue to deal with, PHPCS re-tokenizes the next token after a `function`/`const` keyword to `T_STRING`. This is primarily intended for function/constant declarations, however, it affects import use statements for functions/constants as well if the `function`/`const` keyword is part of a group `use` statement.
That means that, for all PHPCS versions prior to the PHPCS version in which this will be fixed (which is expected to be version 3.5.7 as part of upstream PR 3063), `T_STRING` tokens in a group use statement _may_ in fact be PHP 8.0 identifier name tokens and _may_ also need to be split to extract the last part of the name from the complete name to get the alias.
The existing unit test cover all the above situations.1 parent f4d902b commit 4444dc9
1 file changed
+44
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| |||
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
232 | | - | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
244 | | - | |
| 245 | + | |
245 | 246 | | |
246 | | - | |
| 247 | + | |
247 | 248 | | |
248 | | - | |
| 249 | + | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
252 | | - | |
253 | | - | |
| 253 | + | |
| 254 | + | |
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
| |||
276 | 277 | | |
277 | 278 | | |
278 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
279 | 307 | | |
280 | 308 | | |
281 | | - | |
| 309 | + | |
282 | 310 | | |
283 | 311 | | |
284 | 312 | | |
285 | | - | |
| 313 | + | |
286 | 314 | | |
287 | 315 | | |
288 | 316 | | |
289 | 317 | | |
290 | 318 | | |
291 | 319 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
296 | 324 | | |
297 | 325 | | |
298 | 326 | | |
| |||
301 | 329 | | |
302 | 330 | | |
303 | 331 | | |
304 | | - | |
| 332 | + | |
305 | 333 | | |
306 | 334 | | |
307 | 335 | | |
| |||
314 | 342 | | |
315 | 343 | | |
316 | 344 | | |
317 | | - | |
| 345 | + | |
318 | 346 | | |
319 | 347 | | |
320 | 348 | | |
321 | | - | |
322 | | - | |
| 349 | + | |
| 350 | + | |
323 | 351 | | |
324 | 352 | | |
325 | 353 | | |
| |||
0 commit comments