Skip to content

Commit

Permalink
DX: there is no namespace if there is no PHP code (#7953)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Apr 16, 2024
1 parent 0e9f115 commit 1e6e13b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Tokenizer/Analyzer/NamespacesAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getDeclarations(Tokens $tokens): array
$index = $scopeEndIndex;
}

if (0 === \count($namespaces)) {
if (0 === \count($namespaces) && $tokens->isTokenKindFound(T_OPEN_TAG)) {
$namespaces[] = new NamespaceAnalysis('', '', 0, 0, 0, \count($tokens) - 1);
}

Expand Down
19 changes: 6 additions & 13 deletions tests/Tokenizer/Analyzer/NamespacesAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public static function provideNamespacesCases(): iterable
17
),
]];

yield [
'there is no namespace if there is no PHP code',
[
],
];
}

/**
Expand Down Expand Up @@ -155,19 +161,6 @@ public static function provideGetNamespaceAtCases(): iterable
17
),
];

yield [
' ',
0,
new NamespaceAnalysis(
'',
'',
0,
0,
0,
0
),
];
}

public function testInvalidIndex(): void
Expand Down

0 comments on commit 1e6e13b

Please sign in to comment.