|
8 | 8 | use PhpParser\PrettyPrinter\Standard;
|
9 | 9 | use PHPStan\Analyser\Analyser;
|
10 | 10 | use PHPStan\Analyser\Error;
|
| 11 | +use PHPStan\Analyser\FileAnalyser; |
11 | 12 | use PHPStan\Analyser\NodeScopeResolver;
|
12 | 13 | use PHPStan\Analyser\TypeSpecifier;
|
13 | 14 | use PHPStan\Broker\AnonymousClassNameHelper;
|
14 | 15 | use PHPStan\Cache\Cache;
|
| 16 | +use PHPStan\Dependency\DependencyResolver; |
15 | 17 | use PHPStan\File\FileHelper;
|
16 |
| -use PHPStan\File\FuzzyRelativePathHelper; |
| 18 | +use PHPStan\File\SimpleRelativePathHelper; |
17 | 19 | use PHPStan\PhpDoc\PhpDocNodeResolver;
|
18 | 20 | use PHPStan\PhpDoc\PhpDocStringResolver;
|
19 | 21 | use PHPStan\PhpDoc\TypeNodeResolverExtension;
|
|
31 | 33 | use function implode;
|
32 | 34 | use function sprintf;
|
33 | 35 | use function trim;
|
34 |
| -use const DIRECTORY_SEPARATOR; |
35 | 36 |
|
36 | 37 | /**
|
37 | 38 | * @template TRule of \PHPStan\Rules\Rule
|
@@ -72,38 +73,50 @@ private function getAnalyser(): Analyser
|
72 | 73 | {
|
73 | 74 | if ($this->analyser === null) {
|
74 | 75 | $registry = new Registry([$this->getRule()]);
|
75 |
| - |
76 | 76 | $broker = $this->createBroker();
|
77 | 77 | $printer = new Standard();
|
78 |
| - $fileHelper = $this->getFileHelper(); |
| 78 | + |
| 79 | + $currentWorkingDirectory = $this->getCurrentWorkingDirectory(); |
| 80 | + $fileHelper = new FileHelper($currentWorkingDirectory); |
| 81 | + $relativePathHelper = new SimpleRelativePathHelper($currentWorkingDirectory); |
| 82 | + $anonymousClassNameHelper = new AnonymousClassNameHelper($fileHelper, $relativePathHelper); |
| 83 | + |
79 | 84 | $typeSpecifier = $this->createTypeSpecifier(
|
80 | 85 | $printer,
|
81 | 86 | $broker,
|
82 | 87 | $this->getMethodTypeSpecifyingExtensions(),
|
83 | 88 | $this->getStaticMethodTypeSpecifyingExtensions()
|
84 | 89 | );
|
85 |
| - $currentWorkingDirectory = $this->getCurrentWorkingDirectory(); |
86 |
| - $this->analyser = new Analyser( |
87 |
| - $this->createScopeFactory($broker, $typeSpecifier), |
| 90 | + |
| 91 | + $nodeScopeResolver = new NodeScopeResolver( |
| 92 | + $broker, |
88 | 93 | $this->getParser(),
|
89 |
| - $registry, |
90 |
| - new NodeScopeResolver( |
91 |
| - $broker, |
| 94 | + new FileTypeMapper( |
92 | 95 | $this->getParser(),
|
93 |
| - new FileTypeMapper($this->getParser(), self::getContainer()->getByType(PhpDocStringResolver::class), self::getContainer()->getByType(PhpDocNodeResolver::class), $this->createMock(Cache::class), new AnonymousClassNameHelper(new FileHelper($currentWorkingDirectory), new FuzzyRelativePathHelper($currentWorkingDirectory, DIRECTORY_SEPARATOR, []))), |
94 |
| - $fileHelper, |
95 |
| - $typeSpecifier, |
96 |
| - $this->shouldPolluteScopeWithLoopInitialAssignments(), |
97 |
| - $this->shouldPolluteCatchScopeWithTryAssignments(), |
98 |
| - $this->shouldPolluteScopeWithAlwaysIterableForeach(), |
99 |
| - [], |
100 |
| - [] |
| 96 | + self::getContainer()->getByType(PhpDocStringResolver::class), |
| 97 | + self::getContainer()->getByType(PhpDocNodeResolver::class), |
| 98 | + $this->createMock(Cache::class), |
| 99 | + $anonymousClassNameHelper |
101 | 100 | ),
|
102 | 101 | $fileHelper,
|
| 102 | + $typeSpecifier, |
| 103 | + $this->shouldPolluteScopeWithLoopInitialAssignments(), |
| 104 | + $this->shouldPolluteCatchScopeWithTryAssignments(), |
| 105 | + $this->shouldPolluteScopeWithAlwaysIterableForeach(), |
103 | 106 | [],
|
104 |
| - true, |
105 |
| - 50 |
| 107 | + [] |
106 | 108 | );
|
| 109 | + |
| 110 | + $fileAnalyser = new FileAnalyser( |
| 111 | + $this->createScopeFactory($broker, $typeSpecifier), |
| 112 | + $nodeScopeResolver, |
| 113 | + $this->getParser(), |
| 114 | + new DependencyResolver($broker), |
| 115 | + $fileHelper, |
| 116 | + $this->shouldReportUnmatchedIgnoredErrors() |
| 117 | + ); |
| 118 | + |
| 119 | + $this->analyser = new Analyser($fileAnalyser, $registry, $nodeScopeResolver, 50); |
107 | 120 | }
|
108 | 121 |
|
109 | 122 | return $this->analyser;
|
@@ -137,7 +150,7 @@ public function analyse(string $file): void
|
137 | 150 | {
|
138 | 151 | $file = $this->getFileHelper()->normalizePath($file);
|
139 | 152 | $expectedErrors = $this->parseExpectedErrors($file);
|
140 |
| - $actualErrors = $this->getAnalyser()->analyse([$file], false); |
| 153 | + $actualErrors = $this->getAnalyser()->analyse([$file])->getUnorderedErrors(); |
141 | 154 |
|
142 | 155 | $strictlyTypedSprintf = static function (int $line, string $message): string {
|
143 | 156 | return sprintf('%02d: %s', $line, $message);
|
@@ -210,4 +223,9 @@ protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
|
210 | 223 | return false;
|
211 | 224 | }
|
212 | 225 |
|
| 226 | + protected function shouldReportUnmatchedIgnoredErrors(): bool |
| 227 | + { |
| 228 | + return true; |
| 229 | + } |
| 230 | + |
213 | 231 | }
|
0 commit comments