Skip to content

Commit

Permalink
Remove unnecessary array spread of temp arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonE committed Dec 10, 2024
1 parent 3a4b0e8 commit d9dc810
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/Psalm/ErrorBaseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions src/Psalm/Internal/Analyzer/ScopeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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_) {
Expand All @@ -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_) {
Expand Down Expand Up @@ -199,7 +199,7 @@ public static function getControlActions(
$case_actions = self::getControlActions(
$case->stmts,
$nodes,
[...$break_types, ...['switch']],
[...$break_types, 'switch'],
$return_is_exit,
);

Expand Down Expand Up @@ -256,7 +256,7 @@ public static function getControlActions(
$loop_actions = self::getControlActions(
$stmt->stmts,
$nodes,
[...$break_types, ...['loop']],
[...$break_types, 'loop'],
$return_is_exit,
);

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/DataFlowGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Codebase/TaintFlowGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) .
Expand Down

0 comments on commit d9dc810

Please sign in to comment.