Skip to content

Commit e201714

Browse files
committed
Fix return count in helpers
1 parent 459ab1d commit e201714

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

Inpsyde/Helpers.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public static function isHookFunction(File $file, int $functionPosition): bool
256256
) {
257257
return false;
258258
}
259-
259+
260260
$docTokens = self::filterTokensByType($findDocStart, $findDocEnd, $file, T_DOC_COMMENT_TAG);
261261

262262
foreach ($docTokens as $token) {
@@ -297,27 +297,20 @@ public static function countReturns(File $file, int $functionPosition): array
297297
return [0, 0];
298298
}
299299

300-
$returnTokens = self::filterTokensByType(
301-
$functionStart,
302-
$functionEnd,
303-
$file,
304-
T_RETURN
305-
);
306-
307-
if (!$returnTokens) {
308-
return [0, 0];
309-
}
310-
311300
$nonVoidReturnCount = $voidReturnCount = 0;
312-
$scopeClosers = [];
313-
foreach ($returnTokens as $i => $token) {
314-
if ($scopeClosers && $i === $scopeClosers[0]) {
315-
array_shift($scopeClosers);
301+
$scopeClosers = new \SplStack();
302+
$tokens = $file->getTokens();
303+
for ($i = $functionStart + 1; $i < $functionEnd; $i++) {
304+
if ($scopeClosers->count() && $scopeClosers->top() === $i) {
305+
$scopeClosers->pop();
306+
continue;
316307
}
317-
if ($token['type'] === 'T_FUNCTION') {
318-
array_unshift($scopeClosers, $token['scope_closer']);
308+
if (in_array($tokens[$i]['code'], [T_FUNCTION, T_CLOSURE], true)) {
309+
$scopeClosers->push($tokens[$i]['scope_closer']);
310+
continue;
319311
}
320-
if (!$scopeClosers) {
312+
313+
if (!$scopeClosers->count() && $tokens[$i]['code'] === T_RETURN) {
321314
Helpers::isVoidReturn($file, $i) ? $voidReturnCount++ : $nonVoidReturnCount++;
322315
}
323316
}

0 commit comments

Comments
 (0)