@@ -65,7 +65,14 @@ final class NamespacesAnalyzer
}
if (0 === \count($namespaces) && $tokens->isTokenKindFound(T_OPEN_TAG)) {
- $namespaces[] = new NamespaceAnalysis('', '', 0, 0, 0, \count($tokens) - 1);
+ $namespaces[] = new NamespaceAnalysis(
+ '',
+ $openTagIndex = $tokens[0]->isGivenKind(T_INLINE_HTML) ? 1 : 0,
+ $openTagIndex,
+ \count($tokens) - 1,
+ );
return $namespaces;
@@ -2604,6 +2604,22 @@ use Foo\Bar;
*/
function foo($a) {}',
];
+
+ yield 'with shebang' => [
+ <<<'PHP'
+ #!/usr/bin/env php
+ <?php
+ use Bar\Baz;
+ $foo = new Baz();
+ PHP,
+ $foo = new Bar\Baz();
+ ['import_symbols' => true],
+ ];
/**
@@ -88,10 +88,27 @@ final class NamespacesAnalyzerTest extends TestCase
]];
yield [
- 'there is no namespace if there is no PHP code',
+ #!/usr/bin/php
+ return true;
[
+ new NamespaceAnalysis(
+ 1,
+ 5
+ ),
],
+ yield [
+ 'there is no namespace if there is no PHP code',
+ [],