@@ -1492,14 +1492,33 @@ protected function tokenize($string)
1492
1492
continue ;
1493
1493
}//end if
1494
1494
1495
+ /*
1496
+ Before PHP 5.5, the yield keyword was tokenized as
1497
+ T_STRING. So look for and change this token in
1498
+ earlier versions.
1499
+ */
1500
+
1501
+ if (PHP_VERSION_ID < 50500
1502
+ && $ tokenIsArray === true
1503
+ && $ token [0 ] === T_STRING
1504
+ && strtolower ($ token [1 ]) === 'yield '
1505
+ && isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === false
1506
+ ) {
1507
+ // Could still be "yield from" and potentially multi-line, so adjust the token stack.
1508
+ $ token [0 ] = T_YIELD ;
1509
+
1510
+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
1511
+ echo "\t\t* token $ stackPtr changed from T_STRING to T_YIELD " .PHP_EOL ;
1512
+ }
1513
+ }
1514
+
1495
1515
/*
1496
1516
Before PHP 7.0, the "yield from" was tokenized as
1497
1517
T_YIELD, T_WHITESPACE and T_STRING. So look for
1498
1518
and change this token in earlier versions.
1499
1519
*/
1500
1520
1501
1521
if (PHP_VERSION_ID < 70000
1502
- && PHP_VERSION_ID >= 50500
1503
1522
&& $ tokenIsArray === true
1504
1523
&& $ token [0 ] === T_YIELD
1505
1524
&& isset ($ tokens [($ stackPtr + 1 )]) === true
@@ -1524,51 +1543,6 @@ protected function tokenize($string)
1524
1543
$ tokens [($ stackPtr + 2 )] = null ;
1525
1544
}
1526
1545
1527
- /*
1528
- Before PHP 5.5, the yield keyword was tokenized as
1529
- T_STRING. So look for and change this token in
1530
- earlier versions.
1531
- Checks also if it is just "yield" or "yield from".
1532
- */
1533
-
1534
- if (PHP_VERSION_ID < 50500
1535
- && $ tokenIsArray === true
1536
- && $ token [0 ] === T_STRING
1537
- && strtolower ($ token [1 ]) === 'yield '
1538
- && isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === false
1539
- ) {
1540
- if (isset ($ tokens [($ stackPtr + 1 )]) === true
1541
- && isset ($ tokens [($ stackPtr + 2 )]) === true
1542
- && $ tokens [($ stackPtr + 1 )][0 ] === T_WHITESPACE
1543
- && $ tokens [($ stackPtr + 2 )][0 ] === T_STRING
1544
- && strtolower ($ tokens [($ stackPtr + 2 )][1 ]) === 'from '
1545
- ) {
1546
- // Could be multi-line, so just just the token stack.
1547
- $ token [0 ] = T_YIELD_FROM ;
1548
- $ token [1 ] .= $ tokens [($ stackPtr + 1 )][1 ].$ tokens [($ stackPtr + 2 )][1 ];
1549
-
1550
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
1551
- for ($ i = ($ stackPtr + 1 ); $ i <= ($ stackPtr + 2 ); $ i ++) {
1552
- $ type = Tokens::tokenName ($ tokens [$ i ][0 ]);
1553
- $ content = Common::prepareForOutput ($ tokens [$ i ][1 ]);
1554
- echo "\t\t* token $ i merged into T_YIELD_FROM; was: $ type => $ content " .PHP_EOL ;
1555
- }
1556
- }
1557
-
1558
- $ tokens [($ stackPtr + 1 )] = null ;
1559
- $ tokens [($ stackPtr + 2 )] = null ;
1560
- } else {
1561
- $ newToken = [];
1562
- $ newToken ['code ' ] = T_YIELD ;
1563
- $ newToken ['type ' ] = 'T_YIELD ' ;
1564
- $ newToken ['content ' ] = $ token [1 ];
1565
- $ finalTokens [$ newStackPtr ] = $ newToken ;
1566
-
1567
- $ newStackPtr ++;
1568
- continue ;
1569
- }//end if
1570
- }//end if
1571
-
1572
1546
/*
1573
1547
Before PHP 5.6, the ... operator was tokenized as three
1574
1548
T_STRING_CONCAT tokens in a row. So look for and combine
0 commit comments