Skip to content

Commit

Permalink
Fix PHPDocs in file with #!shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 4, 2022
1 parent 99358d5 commit c87284a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Type/FileTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private function resolvePhpDocStringToDocNode(string $phpDocString): PhpDocNode
private function getNameScopeMap(string $fileName): array
{
if (!isset($this->memoryCache[$fileName])) {
$cacheKey = sprintf('%s-phpdocstring-v14-filename', $fileName);
$cacheKey = sprintf('%s-phpdocstring-v15-shebang', $fileName);
$variableCacheKey = implode(',', array_map(static fn (array $file): string => sprintf('%s-%d', $file['filename'], $file['modifiedTime']), $this->getCachedDependentFilesWithTimestamps($fileName)));
$map = $this->cache->load($cacheKey, $variableCacheKey);

Expand Down Expand Up @@ -382,6 +382,7 @@ function (Node $node) use ($fileName, $lookForTrait, $traitMethodAliases, $origi
&& !$node instanceof Node\Stmt\GroupUse
&& !$node instanceof Node\Stmt\TraitUse
&& !$node instanceof Node\Stmt\TraitUseAdaptation
&& !$node instanceof Node\Stmt\InlineHTML
&& !array_key_exists($nameScopeKey, $nameScopeMap)
) {
$nameScopeMap[$nameScopeKey] = static fn (): NameScope => new NameScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ public function testBug4486Namespace(): void
]);
}

public function testBug6252(): void
{
$this->analyse([__DIR__ . '/data/bug-6252.php'], []);
}

}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-6252.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace foo;

class bar {}

namespace abc;

use foo\bar;

/** @var bar $x */
$x = new bar();

0 comments on commit c87284a

Please sign in to comment.