-
Notifications
You must be signed in to change notification settings - Fork 478
/
Copy pathPathRoutingParser.php
55 lines (43 loc) · 1.42 KB
/
PathRoutingParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php declare(strict_types = 1);
namespace PHPStan\Parser;
use PHPStan\File\FileHelper;
use function array_fill_keys;
use function strpos;
class PathRoutingParser implements Parser
{
private ?string $singleReflectionFile;
/** @var bool[] filePath(string) => bool(true) */
private array $analysedFiles = [];
public function __construct(
private FileHelper $fileHelper,
private Parser $currentPhpVersionRichParser,
private Parser $currentPhpVersionSimpleParser,
private Parser $php8Parser,
?string $singleReflectionFile,
)
{
$this->singleReflectionFile = $singleReflectionFile !== null ? $fileHelper->normalizePath($singleReflectionFile) : null;
}
/**
* @param string[] $files
*/
public function setAnalysedFiles(array $files): void
{
$this->analysedFiles = array_fill_keys($files, true);
}
public function parseFile(string $file): array
{
if (strpos($this->fileHelper->normalizePath($file, '/'), 'vendor/jetbrains/phpstorm-stubs') !== false) {
return $this->php8Parser->parseFile($file);
}
$file = $this->fileHelper->normalizePath($file);
if (!isset($this->analysedFiles[$file]) && $file !== $this->singleReflectionFile) {
return $this->currentPhpVersionSimpleParser->parseFile($file);
}
return $this->currentPhpVersionRichParser->parseFile($file);
}
public function parseString(string $sourceCode): array
{
return $this->currentPhpVersionSimpleParser->parseString($sourceCode);
}
}