Skip to content

Commit b5a2c8f

Browse files
committed
Fix PHPDocs with require statement
1 parent b1f45d0 commit b5a2c8f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

Diff for: src/Type/FileTypeMapper.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private function resolvePhpDocStringToDocNode(string $phpDocString): PhpDocNode
187187
private function getNameScopeMap(string $fileName): array
188188
{
189189
if (!isset($this->memoryCache[$fileName])) {
190-
$cacheKey = sprintf('%s-phpdocstring-v16-look-for-trait', $fileName);
190+
$cacheKey = sprintf('%s-phpdocstring-v17-require-once', $fileName);
191191
$variableCacheKey = implode(',', array_map(static fn (array $file): string => sprintf('%s-%d', $file['filename'], $file['modifiedTime']), $this->getCachedDependentFilesWithTimestamps($fileName)));
192192
$map = $this->cache->load($cacheKey, $variableCacheKey);
193193

@@ -373,6 +373,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
373373
&& !$node instanceof Node\Stmt\TraitUse
374374
&& !$node instanceof Node\Stmt\TraitUseAdaptation
375375
&& !$node instanceof Node\Stmt\InlineHTML
376+
&& !($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Include_)
376377
&& !array_key_exists($nameScopeKey, $nameScopeMap)
377378
) {
378379
$nameScopeMap[$nameScopeKey] = static fn (): NameScope => new NameScope(

Diff for: tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,9 @@ public function testBug6252(): void
146146
$this->analyse([__DIR__ . '/data/bug-6252.php'], []);
147147
}
148148

149+
public function testBug6348(): void
150+
{
151+
$this->analyse([__DIR__ . '/data/bug-6348.php'], []);
152+
}
153+
149154
}

Diff for: tests/PHPStan/Rules/PhpDoc/data/bug-6348.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace fooBug6348;
4+
5+
class bar {}
6+
7+
namespace abcBug6348;
8+
9+
require_once __DIR__ . '/empty.php';
10+
11+
use fooBug6348\bar;
12+
13+
/** @var bar $x */
14+
$x = new bar();

Diff for: tests/PHPStan/Rules/PhpDoc/data/empty.php

Whitespace-only changes.

0 commit comments

Comments
 (0)