Skip to content

Commit

Permalink
Support multiple namespace tokens / Fix token warning on PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Aug 8, 2022
1 parent feca020 commit 36227cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# [1.2.14] = 8 August 2022
### Fixed
- Properly pick up on injected interfaces too
- Support multiple namespace tokens
- Fix token warning on PHP 7.4

# [1.2.13] = 8 August 2022
### Removed
Expand Down
23 changes: 22 additions & 1 deletion Scan/ClassCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function findNamespaceInTokens(array $tokens): string
}

if ($foundNamespace === true) {
if (is_array($token) && in_array((string)$token[0], [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED])) {
if (is_array($token) && in_array((string)$token[0], $this->getNamespaceTokens())) {
$namespace .= $token[1];
} else {
if ($token === ';') {
Expand All @@ -73,6 +73,27 @@ private function findNamespaceInTokens(array $tokens): string

return $namespace;
}

/**
* @return array
*/
private function getNamespaceTokens(): array
{
$namespaceTokens = [T_STRING, T_NS_SEPARATOR];
if (defined('T_NAME_QUALIFIED')) {
$namespaceTokens[] = T_NAME_QUALIFIED;
}

if (defined('T_NAME_FULLY_QUALIFIED')) {
$namespaceTokens[] = T_NAME_FULLY_QUALIFIED;
}

if (defined('T_NAME_RELATIVE')) {
$namespaceTokens[] = T_NAME_RELATIVE;
}

return $namespaceTokens;
}

/**
* @param array $tokens
Expand Down

0 comments on commit 36227cb

Please sign in to comment.