diff --git a/src/Console/Command/WorkerCommand.php b/src/Console/Command/WorkerCommand.php index 0797891592f..0c71fcf60b9 100644 --- a/src/Console/Command/WorkerCommand.php +++ b/src/Console/Command/WorkerCommand.php @@ -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), ]); } diff --git a/src/Error/ErrorsManager.php b/src/Error/ErrorsManager.php index bbf631a59f6..2a42b3c7ff6 100644 --- a/src/Error/ErrorsManager.php +++ b/src/Error/ErrorsManager.php @@ -74,14 +74,13 @@ public function getLintErrors(): array } /** + * Returns errors reported for specified path. + * * @return list */ - 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())); } /** diff --git a/tests/Error/ErrorsManagerTest.php b/tests/Error/ErrorsManagerTest.php index b928dbaf709..f81cdc7e4a3 100644 --- a/tests/Error/ErrorsManagerTest.php +++ b/tests/Error/ErrorsManagerTest.php @@ -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); } }