23
23
use Reflector ;
24
24
use RuntimeException ;
25
25
use UnexpectedValueException ;
26
- use function array_merge ;
27
26
use function file_exists ;
28
27
use function file_get_contents ;
29
28
use function get_class ;
@@ -145,7 +144,8 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
145
144
$ tokens = new ArrayIterator (token_get_all ($ fileContents ));
146
145
147
146
while ($ tokens ->valid ()) {
148
- switch ($ tokens ->current ()[0 ]) {
147
+ $ currentToken = $ tokens ->current ();
148
+ switch ($ currentToken [0 ]) {
149
149
case T_NAMESPACE :
150
150
$ currentNamespace = $ this ->parseNamespace ($ tokens );
151
151
break ;
@@ -156,17 +156,18 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
156
156
$ braceLevel = 0 ;
157
157
$ firstBraceFound = false ;
158
158
while ($ tokens ->valid () && ($ braceLevel > 0 || !$ firstBraceFound )) {
159
- if ($ tokens ->current () === '{ '
160
- || $ tokens ->current ()[0 ] === T_CURLY_OPEN
161
- || $ tokens ->current ()[0 ] === T_DOLLAR_OPEN_CURLY_BRACES ) {
159
+ $ currentToken = $ tokens ->current ();
160
+ if ($ currentToken === '{ '
161
+ || $ currentToken [0 ] === T_CURLY_OPEN
162
+ || $ currentToken [0 ] === T_DOLLAR_OPEN_CURLY_BRACES ) {
162
163
if (!$ firstBraceFound ) {
163
164
$ firstBraceFound = true ;
164
165
}
165
166
166
167
++$ braceLevel ;
167
168
}
168
169
169
- if ($ tokens -> current () === '} ' ) {
170
+ if ($ currentToken === '} ' ) {
170
171
--$ braceLevel ;
171
172
}
172
173
@@ -176,7 +177,7 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
176
177
break ;
177
178
case T_USE :
178
179
if ($ currentNamespace === $ namespace ) {
179
- $ useStatements = array_merge ( $ useStatements , $ this ->parseUseStatement ($ tokens) );
180
+ $ useStatements += $ this ->parseUseStatement ($ tokens );
180
181
}
181
182
182
183
break ;
@@ -218,12 +219,13 @@ private function parseUseStatement(ArrayIterator $tokens) : array
218
219
while (true ) {
219
220
$ this ->skipToNextStringOrNamespaceSeparator ($ tokens );
220
221
221
- $ uses = array_merge ($ uses , $ this ->extractUseStatements ($ tokens ));
222
- if ($ tokens ->current ()[0 ] === self ::T_LITERAL_END_OF_USE ) {
222
+ $ uses += $ this ->extractUseStatements ($ tokens );
223
+ $ currentToken = $ tokens ->current ();
224
+ if ($ currentToken [0 ] === self ::T_LITERAL_END_OF_USE ) {
223
225
return $ uses ;
224
226
}
225
227
226
- if ($ tokens -> current () === false ) {
228
+ if ($ currentToken === false ) {
227
229
break ;
228
230
}
229
231
}
@@ -236,7 +238,12 @@ private function parseUseStatement(ArrayIterator $tokens) : array
236
238
*/
237
239
private function skipToNextStringOrNamespaceSeparator (ArrayIterator $ tokens ) : void
238
240
{
239
- while ($ tokens ->valid () && ($ tokens ->current ()[0 ] !== T_STRING ) && ($ tokens ->current ()[0 ] !== T_NS_SEPARATOR )) {
241
+ while ($ tokens ->valid ()) {
242
+ $ currentToken = $ tokens ->current ();
243
+ if ($ currentToken [0 ] === T_STRING || $ currentToken [0 ] === T_NS_SEPARATOR ) {
244
+ break ;
245
+ }
246
+
240
247
$ tokens ->next ();
241
248
}
242
249
}
0 commit comments