Skip to content

Commit

Permalink
PHPStan Pro - fix for potential issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 20, 2022
1 parent 9044bfc commit 2a145ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ services:
currentPhpVersionRichParser: @currentPhpVersionRichParser
currentPhpVersionSimpleParser: @currentPhpVersionSimpleParser
php8Parser: @php8Parser
singleReflectionFile: %singleReflectionFile%
autowired: false

# Error formatters
Expand Down
6 changes: 5 additions & 1 deletion src/Parser/PathRoutingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class PathRoutingParser implements Parser
{

private ?string $singleReflectionFile;

/** @var bool[] filePath(string) => bool(true) */
private array $analysedFiles = [];

Expand All @@ -17,8 +19,10 @@ public function __construct(
private Parser $currentPhpVersionRichParser,
private Parser $currentPhpVersionSimpleParser,
private Parser $php8Parser,
?string $singleReflectionFile,
)
{
$this->singleReflectionFile = $singleReflectionFile !== null ? $fileHelper->normalizePath($singleReflectionFile) : null;
}

/**
Expand All @@ -36,7 +40,7 @@ public function parseFile(string $file): array
}

$file = $this->fileHelper->normalizePath($file);
if (!isset($this->analysedFiles[$file])) {
if (!isset($this->analysedFiles[$file]) && $file !== $this->singleReflectionFile) {
return $this->currentPhpVersionSimpleParser->parseFile($file);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/PHPStan/Parser/CachedParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function testParseTheSameFileWithDifferentMethod(): void
$fileHelper,
self::getContainer()->getService('currentPhpVersionRichParser'),
self::getContainer()->getService('currentPhpVersionSimpleDirectParser'),
self::getContainer()->getService('php8Parser')
self::getContainer()->getService('php8Parser'),
null
);
$parser = new CachedParser($pathRoutingParser, 500);
$path = $fileHelper->normalizePath(__DIR__ . '/data/test.php');
Expand Down

0 comments on commit 2a145ba

Please sign in to comment.