Skip to content

Commit

Permalink
Fix PHPDocs with require statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 13, 2022
1 parent b1f45d0 commit b5a2c8f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Type/FileTypeMapper.php
Expand Up @@ -187,7 +187,7 @@ private function resolvePhpDocStringToDocNode(string $phpDocString): PhpDocNode
private function getNameScopeMap(string $fileName): array
{
if (!isset($this->memoryCache[$fileName])) {
$cacheKey = sprintf('%s-phpdocstring-v16-look-for-trait', $fileName);
$cacheKey = sprintf('%s-phpdocstring-v17-require-once', $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 @@ -373,6 +373,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
&& !$node instanceof Node\Stmt\TraitUse
&& !$node instanceof Node\Stmt\TraitUseAdaptation
&& !$node instanceof Node\Stmt\InlineHTML
&& !($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Include_)
&& !array_key_exists($nameScopeKey, $nameScopeMap)
) {
$nameScopeMap[$nameScopeKey] = static fn (): NameScope => new NameScope(
Expand Down
Expand Up @@ -146,4 +146,9 @@ public function testBug6252(): void
$this->analyse([__DIR__ . '/data/bug-6252.php'], []);
}

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

}
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-6348.php
@@ -0,0 +1,14 @@
<?php

namespace fooBug6348;

class bar {}

namespace abcBug6348;

require_once __DIR__ . '/empty.php';

use fooBug6348\bar;

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

0 comments on commit b5a2c8f

Please sign in to comment.