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 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<string,array<string,array{o:int, s:array<int, string>}>> $carry
* @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_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:

View File

@ -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,