Skip to content

Commit

Permalink
Revert "minor: ErrorsManager - no need for forPath, but we need getAl…
Browse files Browse the repository at this point in the history
…l instead"

This reverts commit 891df50.
  • Loading branch information
Wirone committed May 7, 2024
1 parent 31acd48 commit 0220bf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function (ConnectionInterface $connection) use ($loop, $runner, $identifier): vo
// @phpstan-ignore-next-line False-positive caused by assigning empty array to $events property
'status' => isset($this->events[0]) ? $this->events[0]->getStatus() : null,
'fixInfo' => $analysisResult[$relativePath] ?? null,
'errors' => $this->errorsManager->popAllErrors(),
'errors' => $this->errorsManager->forPath($absolutePath),
]);
}

Expand Down
9 changes: 4 additions & 5 deletions src/Error/ErrorsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ public function getLintErrors(): array
}

/**
* Returns errors reported for specified path.
*
* @return list<Error>
*/
public function popAllErrors(): array
public function forPath(string $path): array
{
$errors = $this->errors;
$this->errors = [];

return $errors;
return array_values(array_filter($this->errors, static fn (Error $error): bool => $path === $error->getFilePath()));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions tests/Error/ErrorsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ public function testThatCanReportAndRetrieveErrorsForSpecificPath(): void

self::assertFalse($errorsManager->isEmpty());

$errors = $errorsManager->popAllErrors();
self::assertCount(5, $errors);
$errors = $errorsManager->forPath('foo.php');

$errors = $errorsManager->popAllErrors();
self::assertCount(0, $errors);
self::assertCount(3, $errors);
}
}

0 comments on commit 0220bf7

Please sign in to comment.