1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Use array destructuring when possible (#4221)

* list usage

* fix inversion
This commit is contained in:
orklah 2020-09-20 18:55:38 +02:00 committed by Daniil Gentili
parent 69be386072
commit f1aba254be
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
8 changed files with 12 additions and 20 deletions

View File

@ -208,8 +208,7 @@ class ReturnTypeCollector
}
if ($type instanceof Type\Atomic\TArray) {
$key_type_param = $type->type_params[0];
$value_type_param = $type->type_params[1];
[$key_type_param, $value_type_param] = $type->type_params;
if (!$key_type) {
$key_type = clone $key_type_param;

View File

@ -537,8 +537,7 @@ class ForeachAnalyzer
continue;
}
$value_type_part = $iat->type_params[1];
$key_type_part = $iat->type_params[0];
[$key_type_part, $value_type_part] = $iat->type_params;
if (!$intersection_value_type) {
$intersection_value_type = $value_type_part;
@ -835,8 +834,7 @@ class ForeachAnalyzer
$array_atomic_type = $array_atomic_type->getGenericArrayType();
}
$key_type_part = $array_atomic_type->type_params[0];
$value_type_part = $array_atomic_type->type_params[1];
[$key_type_part, $value_type_part] = $array_atomic_type->type_params;
} else {
if ($array_atomic_type instanceof Type\Atomic\TNamedObject
&& $codebase->classExists($array_atomic_type->value)

View File

@ -837,8 +837,8 @@ class CallAnalyzer
$union_comparison_result = new \Psalm\Internal\Type\Comparator\TypeComparisonResult();
if (count($template_result->lower_bounds_unintersectable_types) > 1) {
$upper_bound_type = $template_result->lower_bounds_unintersectable_types[0];
$lower_bound_type = $template_result->lower_bounds_unintersectable_types[1];
[$upper_bound_type, $lower_bound_type]
= $template_result->lower_bounds_unintersectable_types;
}
if (!UnionTypeComparator::isContainedBy(

View File

@ -561,8 +561,7 @@ class ArrayFetchAnalyzer
if (count($key_values) === 1) {
$from_mixed_array = $type->type_params[1]->isMixed();
$previous_key_type = $type->type_params[0];
$previous_value_type = $type->type_params[1];
[$previous_key_type, $previous_value_type] = $type->type_params;
// ok, type becomes an TKeyedArray
$array_type->removeType($type_string);

View File

@ -37,8 +37,7 @@ class UnusedAssignmentRemover
CodeLocation $original_location
): void {
$search_result = $this->findAssignStmt($stmts, $var_id, $original_location);
$assign_stmt = $search_result[0];
$assign_exp = $search_result[1];
[$assign_stmt, $assign_exp] = $search_result;
$chain_assignment = false;
if ($assign_stmt !== null && $assign_exp !== null) {
@ -245,8 +244,7 @@ class UnusedAssignmentRemover
if ($stmt instanceof PhpParser\Node\Stmt\Expression) {
$search_result = $this->findAssignExp($stmt->expr, $var_id, $original_location->raw_file_start);
$target_exp = $search_result[0];
$levels_taken = $search_result[1];
[$target_exp, $levels_taken] = $search_result;
if ($target_exp !== null) {
$assign_exp_found = true;

View File

@ -118,8 +118,7 @@ class ArrayReduceReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturn
return Type::getMixed();
}
$carry_param = $closure_atomic_type->params[0];
$item_param = $closure_atomic_type->params[1];
[$carry_param, $item_param] = $closure_atomic_type->params;
if ($carry_param->type
&& (

View File

@ -366,8 +366,7 @@ class CallableTypeComparator
return 'not-callable';
}
$lhs = $input_type_part->properties[0];
$rhs = $input_type_part->properties[1];
[$lhs, $rhs] = $input_type_part->properties;
$rhs_low_info = $rhs->hasMixed() || $rhs->hasScalar();

View File

@ -293,8 +293,8 @@ class ErrorBaselineTest extends TestCase
/** @var \DOMElement[] $files */
$files = $baselineDocument->getElementsByTagName('files')[0]->childNodes;
$file1 = $files[0];
$file2 = $files[1];
[$file1, $file2] = $files;
$this->assertSame('sample/sample-file.php', $file1->getAttribute('src'));
$this->assertSame('sample/sample-file2.php', $file2->getAttribute('src'));