Skip to content

Commit

Permalink
Introducing PathRoutingParser
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 22, 2020
1 parent afc5092 commit 0f8a61a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
20 changes: 17 additions & 3 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ services:
-
class: PHPStan\Parser\CachedParser
arguments:
originalParser: @currentPhpVersionRichParser
originalParser: @pathRoutingParser
cachedNodesByStringCountMax: %cache.nodesByStringCountMax%

-
Expand Down Expand Up @@ -1302,7 +1302,7 @@ services:
-
class: Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber
arguments:
phpParser: @php8Parser
phpParser: @php8PhpParser
phpVersionId: %phpVersion%
autowired:
- Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber
Expand All @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions src/Parser/PathRoutingParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php declare(strict_types = 1);

namespace PHPStan\Parser;

use PHPStan\File\FileHelper;

class PathRoutingParser implements Parser
{

private FileHelper $fileHelper;

private Parser $currentPhpVersionRichParser;

private Parser $currentPhpVersionSimpleParser;

private Parser $php8Parser;

public function __construct(
FileHelper $fileHelper,
Parser $currentPhpVersionRichParser,
Parser $currentPhpVersionSimpleParser,
Parser $php8Parser
)
{
$this->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);
}

}

0 comments on commit 0f8a61a

Please sign in to comment.