diff --git a/src/Psalm/ErrorBaseline.php b/src/Psalm/ErrorBaseline.php index 2deee69eb..b9a42aba0 100644 --- a/src/Psalm/ErrorBaseline.php +++ b/src/Psalm/ErrorBaseline.php @@ -20,6 +20,8 @@ use RuntimeException; use function str_replace; use function strpos; use function usort; +use function count; +use function array_values; class ErrorBaseline { @@ -198,16 +200,11 @@ class ErrorBaseline */ private static function countIssueTypesByFile(array $issues): array { - $normalized_data = []; - - foreach ($issues as $file_issues) { - foreach ($file_issues as $issue_data) { - $normalized_data[] = $issue_data; - } + if (0 === count($issues)) { + return []; } - $groupedIssues = array_reduce( - $normalized_data, + array_merge(...array_values($issues)), /** * @param array}>> $carry * @param array{type: string, file_name: string, severity: string, selected_text: string} $issue diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index dd1cecba4..bf56c8ee8 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -29,6 +29,8 @@ use function sha1; use function str_repeat; use function str_replace; use function usort; +use function array_merge; +use function array_values; class IssueBuffer { @@ -619,13 +621,7 @@ class IssueBuffer $total_expression_count = $mixed_counts[0] + $mixed_counts[1]; $mixed_expression_count = $mixed_counts[0]; - $normalized_data = []; - - foreach (self::$issues_data as $file_issues) { - foreach ($file_issues as $issue_data) { - $normalized_data[] = $issue_data; - } - } + $normalized_data = 0 === count(self::$issues_data) ? [] : array_merge(...array_values(self::$issues_data)); switch ($report_options->format) { case Report::TYPE_COMPACT: diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index 1b3568d32..91e592a05 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -23,6 +23,9 @@ use Psalm\SourceControl\SourceControlInfo; use const STDERR; use function strlen; use function var_export; +use function count; +use function array_merge; +use function array_values; class Shepherd implements \Psalm\Plugin\Hook\AfterAnalysisInterface { @@ -56,15 +59,15 @@ class Shepherd implements \Psalm\Plugin\Hook\AfterAnalysisInterface unset($build_info['git']); if ($build_info) { - $normalized_data = []; - - foreach ($issues as $file_issues) { - foreach ($file_issues as $issue_data) { - if ($issue_data['severity'] === 'error') { - $normalized_data[] = $issue_data; - } + $normalized_data = 0 === count($issues) ? [] : array_filter( + array_merge(...array_values($issues)), + /** + * @param array{severity: string} $i + */ + static function (array $i) : bool { + return $i['severity'] === 'error'; } - } + ); $data = [ 'build' => $build_info,