Skip to content

Commit

Permalink
Merge pull request #8345 from weirdan/rector-ArraySpreadInsteadOfArra…
Browse files Browse the repository at this point in the history
…yMergeRector-2

Applied ArraySpreadInsteadOfArrayMergeRector (take 2)
  • Loading branch information
orklah committed Jul 30, 2022
2 parents 7c4228f + c9e6b54 commit f5b7a56
Show file tree
Hide file tree
Showing 52 changed files with 417 additions and 472 deletions.
3 changes: 1 addition & 2 deletions src/Psalm/Codebase.php
Expand Up @@ -67,7 +67,6 @@
use UnexpectedValueException;

use function array_combine;
use function array_merge;
use function array_pop;
use function array_reverse;
use function count;
Expand Down Expand Up @@ -618,7 +617,7 @@ public function findReferencesToClassLike(string $fq_class_name): array
$locations = $this->file_reference_provider->getClassLocations($fq_class_name_lc);

if (isset($this->use_referencing_locations[$fq_class_name_lc])) {
$locations = array_merge($locations, $this->use_referencing_locations[$fq_class_name_lc]);
$locations = [...$locations, ...$this->use_referencing_locations[$fq_class_name_lc]];
}

return $locations;
Expand Down
5 changes: 1 addition & 4 deletions src/Psalm/Config/Creator.php
Expand Up @@ -246,10 +246,7 @@ private static function getPsr4Or0Paths(string $current_dir, array $composer_jso

foreach ($paths as $path) {
if ($path === '') {
$nodes = array_merge(
$nodes,
self::guessPhpFileDirs($current_dir)
);
$nodes = [...$nodes, ...self::guessPhpFileDirs($current_dir)];

continue;
}
Expand Down
17 changes: 7 additions & 10 deletions src/Psalm/ErrorBaseline.php
Expand Up @@ -249,19 +249,16 @@ private static function writeToFile(
$filesNode->setAttribute('psalm-version', PSALM_VERSION);

if ($include_php_versions) {
$extensions = array_merge(get_loaded_extensions(), get_loaded_extensions(true));
$extensions = [...get_loaded_extensions(), ...get_loaded_extensions(true)];

usort($extensions, 'strnatcasecmp');

$filesNode->setAttribute('php-version', implode(';' . "\n\t", array_merge(
[
('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
6 changes: 1 addition & 5 deletions src/Psalm/Internal/Algebra/FormulaGenerator.php
Expand Up @@ -14,7 +14,6 @@
use Psalm\Node\Expr\VirtualBooleanNot;
use Psalm\Storage\Assertion\Truthy;

use function array_merge;
use function count;
use function spl_object_id;
use function substr;
Expand Down Expand Up @@ -62,10 +61,7 @@ public static function getFormula(
$cache
);

return array_merge(
$left_assertions,
$right_assertions
);
return [...$left_assertions, ...$right_assertions];
}

if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
Expand Down
108 changes: 54 additions & 54 deletions src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php
Expand Up @@ -94,138 +94,138 @@ public static function getReturnTypes(
}

if ($stmt->expr instanceof PhpParser\Node\Expr\Assign) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
[$stmt->expr->expr],
$yield_types
)
);
];
}

$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($stmt->expr, $nodes));
} elseif ($stmt instanceof PhpParser\Node\Stmt\If_) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];

foreach ($stmt->elseifs as $elseif) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$elseif->stmts,
$yield_types
)
);
];
}

if ($stmt->else) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->else->stmts,
$yield_types
)
);
];
}
} elseif ($stmt instanceof PhpParser\Node\Stmt\TryCatch) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];

foreach ($stmt->catches as $catch) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$catch->stmts,
$yield_types
)
);
];
}

if ($stmt->finally) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->finally->stmts,
$yield_types
)
);
];
}
} elseif ($stmt instanceof PhpParser\Node\Stmt\For_) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];
} elseif ($stmt instanceof PhpParser\Node\Stmt\Foreach_) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];
} elseif ($stmt instanceof PhpParser\Node\Stmt\While_) {
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($stmt->cond, $nodes));
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];
} elseif ($stmt instanceof PhpParser\Node\Stmt\Do_) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$stmt->stmts,
$yield_types
)
);
];
} elseif ($stmt instanceof PhpParser\Node\Stmt\Switch_) {
foreach ($stmt->cases as $case) {
$return_types = array_merge(
$return_types,
self::getReturnTypes(
$return_types = [
...$return_types,
...self::getReturnTypes(
$codebase,
$nodes,
$case->stmts,
$yield_types
)
);
];
}
}
}
Expand Down Expand Up @@ -339,10 +339,10 @@ protected static function getYieldTypeFromExpression(
}

if ($stmt instanceof PhpParser\Node\Expr\BinaryOp) {
return array_merge(
self::getYieldTypeFromExpression($stmt->left, $nodes),
self::getYieldTypeFromExpression($stmt->right, $nodes)
);
return [
...self::getYieldTypeFromExpression($stmt->left, $nodes),
...self::getYieldTypeFromExpression($stmt->right, $nodes)
];
}

if ($stmt instanceof PhpParser\Node\Expr\Assign) {
Expand All @@ -361,7 +361,7 @@ protected static function getYieldTypeFromExpression(
$yield_types = [];

foreach ($stmt->getArgs() as $arg) {
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($arg->value, $nodes));
$yield_types = [...$yield_types, ...self::getYieldTypeFromExpression($arg->value, $nodes)];
}

return $yield_types;
Expand All @@ -372,7 +372,7 @@ protected static function getYieldTypeFromExpression(

foreach ($stmt->items as $item) {
if ($item instanceof PhpParser\Node\Expr\ArrayItem) {
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($item->value, $nodes));
$yield_types = [...$yield_types, ...self::getYieldTypeFromExpression($item->value, $nodes)];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -619,7 +619,7 @@ public function check(string $base_dir, bool $is_diff = false): void
&& $this->project_cache_provider->canDiffFiles()
) {
$deleted_files = $this->file_reference_provider->getDeletedReferencedFiles();
$diff_files = array_merge($deleted_files, $this->getDiffFiles());
$diff_files = [...$deleted_files, ...$this->getDiffFiles()];
}

$this->progress->write($this->generatePHPVersionMessage());
Expand Down

0 comments on commit f5b7a56

Please sign in to comment.