Skip to content

Commit

Permalink
RuleTestCase - call getRule() only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 22, 2024
1 parent 1d2575d commit dfbf8d0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Testing/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ protected function getTypeSpecifier(): TypeSpecifier
return self::getContainer()->getService('typeSpecifier');
}

private function getAnalyser(): Analyser
private function getAnalyser(DirectRuleRegistry $ruleRegistry): Analyser
{
if ($this->analyser === null) {
$ruleRegistry = new DirectRuleRegistry([
$this->getRule(),
]);
$collectorRegistry = new CollectorRegistry($this->getCollectors());

$reflectionProvider = $this->createReflectionProvider();
Expand Down Expand Up @@ -166,8 +163,11 @@ static function (Error $error) use ($strictlyTypedSprintf): string {
*/
public function gatherAnalyserErrors(array $files): array
{
$ruleRegistry = new DirectRuleRegistry([
$this->getRule(),
]);
$files = array_map([$this->getFileHelper(), 'normalizePath'], $files);
$analyserResult = $this->getAnalyser()->analyse(
$analyserResult = $this->getAnalyser($ruleRegistry)->analyse(
$files,
null,
null,
Expand All @@ -178,9 +178,7 @@ public function gatherAnalyserErrors(array $files): array
}

$finalizer = new AnalyserResultFinalizer(
new DirectRuleRegistry([
$this->getRule(),
]),
$ruleRegistry,
new RuleErrorTransformer(),
$this->createScopeFactory($this->createReflectionProvider(), $this->getTypeSpecifier()),
new LocalIgnoresProcessor(),
Expand Down

0 comments on commit dfbf8d0

Please sign in to comment.