From d9dc810e73eb6707896b8c46afa2919c817c744c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Wed, 11 Dec 2024 00:51:21 +0100 Subject: [PATCH] Remove unnecessary array spread of temp arrays --- src/Psalm/ErrorBaseline.php | 13 ++++++----- src/Psalm/Internal/Analyzer/ScopeAnalyzer.php | 22 +++++++++---------- src/Psalm/Internal/Codebase/DataFlowGraph.php | 2 +- .../Internal/Codebase/TaintFlowGraph.php | 4 ++-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Psalm/ErrorBaseline.php b/src/Psalm/ErrorBaseline.php index 783ef4a8c84..7f1199a1a32 100644 --- a/src/Psalm/ErrorBaseline.php +++ b/src/Psalm/ErrorBaseline.php @@ -246,12 +246,13 @@ private static function writeToFile( usort($extensions, 'strnatcasecmp'); - $filesNode->setAttribute('php-version', implode(';' . "\n\t", [...[ - ('php:' . PHP_VERSION), - ], ...array_map( - static fn(string $extension): string => $extension . ':' . phpversion($extension), - $extensions, - )])); + $filesNode->setAttribute('php-version', implode(';' . "\n\t", [ + 'php:' . PHP_VERSION, + ...array_map( + static fn(string $extension): string => $extension . ':' . phpversion($extension), + $extensions, + ), + ])); } foreach ($groupedIssues as $file => $issueTypes) { diff --git a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php index 808010d09bc..04c10111611 100644 --- a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php @@ -59,13 +59,13 @@ public static function getControlActions( // don't consider a return if the expression never returns (e.g. a throw inside a short closure) if ($stmt_return_type && $stmt_return_type->isNever()) { - return array_values(array_unique([...$control_actions, ...[self::ACTION_END]])); + return array_values(array_unique([...$control_actions, self::ACTION_END])); } - return array_values(array_unique([...$control_actions, ...[self::ACTION_RETURN]])); + return array_values(array_unique([...$control_actions, self::ACTION_RETURN])); } - return array_values(array_unique([...$control_actions, ...[self::ACTION_END]])); + return array_values(array_unique([...$control_actions, self::ACTION_END])); } if ($stmt instanceof PhpParser\Node\Stmt\Expression) { @@ -74,7 +74,7 @@ public static function getControlActions( && ($stmt_expr_type = $nodes->getType($stmt->expr)) && $stmt_expr_type->isNever() ) { - return array_values(array_unique([...$control_actions, ...[self::ACTION_END]])); + return array_values(array_unique([...$control_actions, self::ACTION_END])); } continue; @@ -88,13 +88,13 @@ public static function getControlActions( if ($break_types && $count !== null && count($break_types) >= $count) { /** @psalm-suppress InvalidArrayOffset Some int-range improvements are needed */ if ($break_types[count($break_types) - $count] === 'switch') { - return [...$control_actions, ...[self::ACTION_LEAVE_SWITCH]]; + return [...$control_actions, self::ACTION_LEAVE_SWITCH]; } return array_values($control_actions); } - return array_values(array_unique([...$control_actions, ...[self::ACTION_CONTINUE]])); + return array_values(array_unique([...$control_actions, self::ACTION_CONTINUE])); } if ($stmt instanceof PhpParser\Node\Stmt\Break_) { @@ -105,18 +105,18 @@ public static function getControlActions( if ($break_types && $count !== null && count($break_types) >= $count) { /** @psalm-suppress InvalidArrayOffset Some int-range improvements are needed */ if ($break_types[count($break_types) - $count] === 'switch') { - return [...$control_actions, ...[self::ACTION_LEAVE_SWITCH]]; + return [...$control_actions, self::ACTION_LEAVE_SWITCH]; } /** @psalm-suppress InvalidArrayOffset Some int-range improvements are needed */ if ($break_types[count($break_types) - $count] === 'loop') { - return [...$control_actions, ...[self::ACTION_LEAVE_LOOP]]; + return [...$control_actions, self::ACTION_LEAVE_LOOP]; } return array_values($control_actions); } - return array_values(array_unique([...$control_actions, ...[self::ACTION_BREAK]])); + return array_values(array_unique([...$control_actions, self::ACTION_BREAK])); } if ($stmt instanceof PhpParser\Node\Stmt\If_) { @@ -199,7 +199,7 @@ public static function getControlActions( $case_actions = self::getControlActions( $case->stmts, $nodes, - [...$break_types, ...['switch']], + [...$break_types, 'switch'], $return_is_exit, ); @@ -256,7 +256,7 @@ public static function getControlActions( $loop_actions = self::getControlActions( $stmt->stmts, $nodes, - [...$break_types, ...['loop']], + [...$break_types, 'loop'], $return_is_exit, ); diff --git a/src/Psalm/Internal/Codebase/DataFlowGraph.php b/src/Psalm/Internal/Codebase/DataFlowGraph.php index 6a79fa7e2bf..40936a02e41 100644 --- a/src/Psalm/Internal/Codebase/DataFlowGraph.php +++ b/src/Psalm/Internal/Codebase/DataFlowGraph.php @@ -154,7 +154,7 @@ public function summarizeEdges(): array $edges = []; foreach ($this->forward_edges as $source => $destinations) { - $edges[] = [...[$source], ...array_keys($destinations)]; + $edges[] = [$source, ...array_keys($destinations)]; } return $edges; diff --git a/src/Psalm/Internal/Codebase/TaintFlowGraph.php b/src/Psalm/Internal/Codebase/TaintFlowGraph.php index bb7cd993879..008975a9e91 100644 --- a/src/Psalm/Internal/Codebase/TaintFlowGraph.php +++ b/src/Psalm/Internal/Codebase/TaintFlowGraph.php @@ -189,7 +189,7 @@ public function getIssueTrace(DataFlowNode $source): array return []; } - return [...$this->getIssueTrace($previous_source), ...[$node]]; + return [...$this->getIssueTrace($previous_source), $node]; } return [$node]; @@ -467,7 +467,7 @@ private function getChildNodes( $new_destination->previous = $generated_source; $new_destination->taints = $new_taints; $new_destination->specialized_calls = $generated_source->specialized_calls; - $new_destination->path_types = [...$generated_source->path_types, ...[$path_type]]; + $new_destination->path_types = [...$generated_source->path_types, $path_type]; $key = $to_id . ' ' . json_encode($new_destination->specialized_calls, JSON_THROW_ON_ERROR) .