@@ -80,20 +80,30 @@ public function process(File $phpcsFile, $stackPtr)
80
80
if ($ tokens [$ stackPtr ]['code ' ] === T_YIELD_FROM
81
81
&& strtolower ($ content ) !== 'yield from '
82
82
) {
83
- if ($ tokens [($ stackPtr - 1 )]['code ' ] === T_YIELD_FROM ) {
84
- // A multi-line statement that has already been processed.
85
- return ;
86
- }
83
+ $ found = $ content ;
84
+ $ hasComment = false ;
85
+ $ yieldFromEnd = $ stackPtr ;
86
+
87
+ // Handle potentially multi-line/multi-token "yield from" expressions.
88
+ if (preg_match ('`yield\s+from`i ' , $ content ) !== 1 ) {
89
+ for ($ i = ($ stackPtr + 1 ); $ i < $ phpcsFile ->numTokens ; $ i ++) {
90
+ if (isset (Tokens::$ emptyTokens [$ tokens [$ i ]['code ' ]]) === false
91
+ && $ tokens [$ i ]['code ' ] !== T_YIELD_FROM
92
+ ) {
93
+ break ;
94
+ }
87
95
88
- $ found = $ content ;
89
- if ($ tokens [($ stackPtr + 1 )]['code ' ] === T_YIELD_FROM ) {
90
- // This yield from statement is split over multiple lines.
91
- $ i = ($ stackPtr + 1 );
92
- do {
93
96
$ found .= $ tokens [$ i ]['content ' ];
94
- $ i ++;
95
- } while ($ tokens [$ i ]['code ' ] === T_YIELD_FROM );
96
- }
97
+
98
+ if ($ tokens [$ i ]['code ' ] === T_YIELD_FROM
99
+ && strtolower (trim ($ tokens [$ i ]['content ' ])) === 'from '
100
+ ) {
101
+ break ;
102
+ }
103
+ }
104
+
105
+ $ yieldFromEnd = $ i ;
106
+ }//end if
97
107
98
108
$ error = 'Language constructs must be followed by a single space; expected 1 space between YIELD FROM found "%s" ' ;
99
109
$ data = [Common::prepareForOutput ($ found )];
@@ -104,18 +114,14 @@ public function process(File $phpcsFile, $stackPtr)
104
114
$ phpcsFile ->fixer ->beginChangeset ();
105
115
$ phpcsFile ->fixer ->replaceToken ($ stackPtr , $ yield [0 ].' ' .$ from [0 ]);
106
116
107
- if ($ tokens [($ stackPtr + 1 )]['code ' ] === T_YIELD_FROM ) {
108
- $ i = ($ stackPtr + 1 );
109
- do {
110
- $ phpcsFile ->fixer ->replaceToken ($ i , '' );
111
- $ i ++;
112
- } while ($ tokens [$ i ]['code ' ] === T_YIELD_FROM );
117
+ for ($ i = ($ stackPtr + 1 ); $ i <= $ yieldFromEnd ; $ i ++) {
118
+ $ phpcsFile ->fixer ->replaceToken ($ i , '' );
113
119
}
114
120
115
121
$ phpcsFile ->fixer ->endChangeset ();
116
122
}
117
123
118
- return ;
124
+ return ( $ yieldFromEnd + 1 ) ;
119
125
}//end if
120
126
121
127
if ($ tokens [($ stackPtr + 1 )]['code ' ] === T_WHITESPACE ) {
0 commit comments