diff --git a/conf/config.neon b/conf/config.neon index a67f8025a8..063c68b2de 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -519,7 +519,7 @@ services: - class: PHPStan\Parser\CachedParser arguments: - originalParser: @currentPhpVersionRichParser + originalParser: @pathRoutingParser cachedNodesByStringCountMax: %cache.nodesByStringCountMax% - @@ -1302,7 +1302,7 @@ services: - class: Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber arguments: - phpParser: @php8Parser + phpParser: @php8PhpParser phpVersionId: %phpVersion% autowired: - Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber @@ -1316,12 +1316,26 @@ services: class: PhpParser\Lexer\Emulative autowired: false - php8Parser: + php8PhpParser: class: PhpParser\Parser\Php7 arguments: lexer: @php8Lexer autowired: false + php8Parser: + class: PHPStan\Parser\SimpleParser + arguments: + parser: @php8PhpParser + autowired: false + + pathRoutingParser: + class: PHPStan\Parser\PathRoutingParser + arguments: + currentPhpVersionRichParser: @currentPhpVersionRichParser + currentPhpVersionSimpleParser: @currentPhpVersionSimpleParser + php8Parser: @php8Parser + autowired: false + # Error formatters errorFormatter.raw: diff --git a/src/Parser/PathRoutingParser.php b/src/Parser/PathRoutingParser.php new file mode 100644 index 0000000000..dfb8db602d --- /dev/null +++ b/src/Parser/PathRoutingParser.php @@ -0,0 +1,46 @@ +fileHelper = $fileHelper; + $this->currentPhpVersionRichParser = $currentPhpVersionRichParser; + $this->currentPhpVersionSimpleParser = $currentPhpVersionSimpleParser; + $this->php8Parser = $php8Parser; + } + + public function parseFile(string $file): array + { + $file = $this->fileHelper->normalizePath($file, '/'); + if (strpos($file, 'vendor/jetbrains/phpstorm-stubs') !== false) { + return $this->php8Parser->parseFile($file); + } + + return $this->currentPhpVersionRichParser->parseFile($file); + } + + public function parseString(string $sourceCode): array + { + return $this->currentPhpVersionRichParser->parseString($sourceCode); + } + +}