From 0220bf7052fc65b7a4c37fe4227ea9a4d4b72ac9 Mon Sep 17 00:00:00 2001 From: Greg Korba Date: Tue, 7 May 2024 23:30:03 +0200 Subject: [PATCH] Revert "minor: ErrorsManager - no need for forPath, but we need getAll instead" This reverts commit 891df5023ce0b4ebdf66e543cd5101bbcfa409af. --- src/Console/Command/WorkerCommand.php | 2 +- src/Error/ErrorsManager.php | 9 ++++----- tests/Error/ErrorsManagerTest.php | 6 ++---- 3 files changed, 7 insertions(+), 10 deletions(-) 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); } }