From 2fa943a8a68f14df44fa86402d8406705644af40 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Wed, 31 May 2023 12:24:49 +0200 Subject: [PATCH 1/2] Shepherd: send a list of issues (instead of array with int keys) as result Shepherd will send an array is issues instead of object with "random" numeric keys --- src/Psalm/Plugin/EventHandler/Event/AfterAnalysisEvent.php | 6 +++--- src/Psalm/Plugin/Shepherd.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Plugin/EventHandler/Event/AfterAnalysisEvent.php b/src/Psalm/Plugin/EventHandler/Event/AfterAnalysisEvent.php index 92ac8ae9b79..60db94732b0 100644 --- a/src/Psalm/Plugin/EventHandler/Event/AfterAnalysisEvent.php +++ b/src/Psalm/Plugin/EventHandler/Event/AfterAnalysisEvent.php @@ -10,7 +10,7 @@ final class AfterAnalysisEvent { private Codebase $codebase; /** - * @var IssueData[][] + * @var array> where string key is a filepath */ private array $issues; private array $build_info; @@ -19,7 +19,7 @@ final class AfterAnalysisEvent /** * Called after analysis is complete * - * @param array> $issues + * @param array> $issues where string key is a filepath * @internal */ public function __construct( @@ -40,7 +40,7 @@ public function getCodebase(): Codebase } /** - * @return IssueData[][] + * @return array> where string key is a filepath */ public function getIssues(): array { diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index 73cbdac4afb..08c6b25d08c 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -121,10 +121,10 @@ private static function collectPayloadToSend(AfterAnalysisEvent $event): ?array } $issues = $event->getIssues(); - $normalized_data = $issues === [] ? [] : array_filter( - array_merge(...array_values($issues)), + $normalized_data = $issues === [] ? [] : array_values(array_filter( + array_merge(...array_values($issues)), // flatten an array static fn(IssueData $i): bool => $i->severity === 'error', - ); + )); $codebase = $event->getCodebase(); From 7b7d823b07facb2699d817fa3653f30118c4f20b Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Thu, 1 Jun 2023 10:51:10 +0200 Subject: [PATCH 2/2] Use better var name --- src/Psalm/Plugin/Shepherd.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index f5d85b5eb06..49dc628e9b3 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -120,9 +120,9 @@ private static function collectPayloadToSend(AfterAnalysisEvent $event): ?array return null; } - $issues = $event->getIssues(); - $normalized_data = $issues === [] ? [] : array_values(array_filter( - array_merge(...array_values($issues)), // flatten an array + $issues_grouped_by_filename = $event->getIssues(); + $normalized_data = $issues_grouped_by_filename === [] ? [] : array_values(array_filter( + array_merge(...array_values($issues_grouped_by_filename)), // flatten an array static fn(IssueData $i): bool => $i->severity === IssueData::SEVERITY_ERROR, ));