Skip to content

Commit

Permalink
Optimize the namespaces analyzer
Browse files Browse the repository at this point in the history
Instead of looping on all tokens, even inside the namespace it identified,
the analyzer now continues the analysis after the end of the identified
namespace, thanks to the fact that namespaces cannot be nested.
  • Loading branch information
stof committed Jul 5, 2018
1 parent 4cee75b commit d75a514
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Tokenizer/Analyzer/NamespacesAnalyzer.php
Expand Up @@ -29,7 +29,9 @@ public function getDeclarations(Tokens $tokens)
{
$namespaces = [];

foreach ($tokens as $index => $token) {
for ($index = 1, $count = \count($tokens); $index < $count; ++$index) {
$token = $tokens[$index];

if (!$token->isGivenKind(T_NAMESPACE)) {
continue;
}
Expand Down Expand Up @@ -57,6 +59,9 @@ public function getDeclarations(Tokens $tokens)
$index,
$scopeEndIndex
);

// Continue the analysis after the end of this namespace to find the next one
$index = $scopeEndIndex;
}

if (0 === count($namespaces)) {
Expand Down

0 comments on commit d75a514

Please sign in to comment.