1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

remove unnecessary loops (#2671)

This commit is contained in:
Ben Davies 2020-01-22 12:42:00 +00:00 committed by Matthew Brown
parent d4ceabc174
commit 5139d61171
3 changed files with 19 additions and 23 deletions

View File

@ -20,6 +20,8 @@ use RuntimeException;
use function str_replace; use function str_replace;
use function strpos; use function strpos;
use function usort; use function usort;
use function count;
use function array_values;
class ErrorBaseline class ErrorBaseline
{ {
@ -198,16 +200,11 @@ class ErrorBaseline
*/ */
private static function countIssueTypesByFile(array $issues): array private static function countIssueTypesByFile(array $issues): array
{ {
$normalized_data = []; if (0 === count($issues)) {
return [];
foreach ($issues as $file_issues) {
foreach ($file_issues as $issue_data) {
$normalized_data[] = $issue_data;
}
} }
$groupedIssues = array_reduce( $groupedIssues = array_reduce(
$normalized_data, array_merge(...array_values($issues)),
/** /**
* @param array<string,array<string,array{o:int, s:array<int, string>}>> $carry * @param array<string,array<string,array{o:int, s:array<int, string>}>> $carry
* @param array{type: string, file_name: string, severity: string, selected_text: string} $issue * @param array{type: string, file_name: string, severity: string, selected_text: string} $issue

View File

@ -29,6 +29,8 @@ use function sha1;
use function str_repeat; use function str_repeat;
use function str_replace; use function str_replace;
use function usort; use function usort;
use function array_merge;
use function array_values;
class IssueBuffer class IssueBuffer
{ {
@ -619,13 +621,7 @@ class IssueBuffer
$total_expression_count = $mixed_counts[0] + $mixed_counts[1]; $total_expression_count = $mixed_counts[0] + $mixed_counts[1];
$mixed_expression_count = $mixed_counts[0]; $mixed_expression_count = $mixed_counts[0];
$normalized_data = []; $normalized_data = 0 === count(self::$issues_data) ? [] : array_merge(...array_values(self::$issues_data));
foreach (self::$issues_data as $file_issues) {
foreach ($file_issues as $issue_data) {
$normalized_data[] = $issue_data;
}
}
switch ($report_options->format) { switch ($report_options->format) {
case Report::TYPE_COMPACT: case Report::TYPE_COMPACT:

View File

@ -23,6 +23,9 @@ use Psalm\SourceControl\SourceControlInfo;
use const STDERR; use const STDERR;
use function strlen; use function strlen;
use function var_export; use function var_export;
use function count;
use function array_merge;
use function array_values;
class Shepherd implements \Psalm\Plugin\Hook\AfterAnalysisInterface class Shepherd implements \Psalm\Plugin\Hook\AfterAnalysisInterface
{ {
@ -56,15 +59,15 @@ class Shepherd implements \Psalm\Plugin\Hook\AfterAnalysisInterface
unset($build_info['git']); unset($build_info['git']);
if ($build_info) { if ($build_info) {
$normalized_data = []; $normalized_data = 0 === count($issues) ? [] : array_filter(
array_merge(...array_values($issues)),
foreach ($issues as $file_issues) { /**
foreach ($file_issues as $issue_data) { * @param array{severity: string} $i
if ($issue_data['severity'] === 'error') { */
$normalized_data[] = $issue_data; static function (array $i) : bool {
} return $i['severity'] === 'error';
} }
} );
$data = [ $data = [
'build' => $build_info, 'build' => $build_info,