Skip to content

Commit c87284a

Browse files
committed
Fix PHPDocs in file with #!shebang
1 parent 99358d5 commit c87284a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Type/FileTypeMapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private function resolvePhpDocStringToDocNode(string $phpDocString): PhpDocNode
204204
private function getNameScopeMap(string $fileName): array
205205
{
206206
if (!isset($this->memoryCache[$fileName])) {
207-
$cacheKey = sprintf('%s-phpdocstring-v14-filename', $fileName);
207+
$cacheKey = sprintf('%s-phpdocstring-v15-shebang', $fileName);
208208
$variableCacheKey = implode(',', array_map(static fn (array $file): string => sprintf('%s-%d', $file['filename'], $file['modifiedTime']), $this->getCachedDependentFilesWithTimestamps($fileName)));
209209
$map = $this->cache->load($cacheKey, $variableCacheKey);
210210

@@ -382,6 +382,7 @@ function (Node $node) use ($fileName, $lookForTrait, $traitMethodAliases, $origi
382382
&& !$node instanceof Node\Stmt\GroupUse
383383
&& !$node instanceof Node\Stmt\TraitUse
384384
&& !$node instanceof Node\Stmt\TraitUseAdaptation
385+
&& !$node instanceof Node\Stmt\InlineHTML
385386
&& !array_key_exists($nameScopeKey, $nameScopeMap)
386387
) {
387388
$nameScopeMap[$nameScopeKey] = static fn (): NameScope => new NameScope(

tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ public function testBug4486Namespace(): void
137137
]);
138138
}
139139

140+
public function testBug6252(): void
141+
{
142+
$this->analyse([__DIR__ . '/data/bug-6252.php'], []);
143+
}
144+
140145
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
namespace foo;
7+
8+
class bar {}
9+
10+
namespace abc;
11+
12+
use foo\bar;
13+
14+
/** @var bar $x */
15+
$x = new bar();

0 commit comments

Comments
 (0)