Skip to content

Commit 0f8a61a

Browse files
committed
Introducing PathRoutingParser
1 parent afc5092 commit 0f8a61a

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

conf/config.neon

+17-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ services:
519519
-
520520
class: PHPStan\Parser\CachedParser
521521
arguments:
522-
originalParser: @currentPhpVersionRichParser
522+
originalParser: @pathRoutingParser
523523
cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
524524

525525
-
@@ -1302,7 +1302,7 @@ services:
13021302
-
13031303
class: Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber
13041304
arguments:
1305-
phpParser: @php8Parser
1305+
phpParser: @php8PhpParser
13061306
phpVersionId: %phpVersion%
13071307
autowired:
13081308
- Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber
@@ -1316,12 +1316,26 @@ services:
13161316
class: PhpParser\Lexer\Emulative
13171317
autowired: false
13181318

1319-
php8Parser:
1319+
php8PhpParser:
13201320
class: PhpParser\Parser\Php7
13211321
arguments:
13221322
lexer: @php8Lexer
13231323
autowired: false
13241324

1325+
php8Parser:
1326+
class: PHPStan\Parser\SimpleParser
1327+
arguments:
1328+
parser: @php8PhpParser
1329+
autowired: false
1330+
1331+
pathRoutingParser:
1332+
class: PHPStan\Parser\PathRoutingParser
1333+
arguments:
1334+
currentPhpVersionRichParser: @currentPhpVersionRichParser
1335+
currentPhpVersionSimpleParser: @currentPhpVersionSimpleParser
1336+
php8Parser: @php8Parser
1337+
autowired: false
1338+
13251339
# Error formatters
13261340

13271341
errorFormatter.raw:

src/Parser/PathRoutingParser.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Parser;
4+
5+
use PHPStan\File\FileHelper;
6+
7+
class PathRoutingParser implements Parser
8+
{
9+
10+
private FileHelper $fileHelper;
11+
12+
private Parser $currentPhpVersionRichParser;
13+
14+
private Parser $currentPhpVersionSimpleParser;
15+
16+
private Parser $php8Parser;
17+
18+
public function __construct(
19+
FileHelper $fileHelper,
20+
Parser $currentPhpVersionRichParser,
21+
Parser $currentPhpVersionSimpleParser,
22+
Parser $php8Parser
23+
)
24+
{
25+
$this->fileHelper = $fileHelper;
26+
$this->currentPhpVersionRichParser = $currentPhpVersionRichParser;
27+
$this->currentPhpVersionSimpleParser = $currentPhpVersionSimpleParser;
28+
$this->php8Parser = $php8Parser;
29+
}
30+
31+
public function parseFile(string $file): array
32+
{
33+
$file = $this->fileHelper->normalizePath($file, '/');
34+
if (strpos($file, 'vendor/jetbrains/phpstorm-stubs') !== false) {
35+
return $this->php8Parser->parseFile($file);
36+
}
37+
38+
return $this->currentPhpVersionRichParser->parseFile($file);
39+
}
40+
41+
public function parseString(string $sourceCode): array
42+
{
43+
return $this->currentPhpVersionRichParser->parseString($sourceCode);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)