1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Remove some array_values

This commit is contained in:
Daniil Gentili 2021-11-26 13:48:38 +01:00
parent 04bbd2acba
commit ee8c5c9c35
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
6 changed files with 29 additions and 34 deletions

View File

@ -130,28 +130,26 @@ class IfElseAnalyzer
$if_clauses = [];
}
$if_clauses = array_values(
array_map(
$if_clauses = array_map(
/**
* @return Clause
*/
function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause {
$keys = array_keys($c->possibilities);
function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause {
$keys = array_keys($c->possibilities);
$mixed_var_ids = \array_diff($mixed_var_ids, $keys);
$mixed_var_ids = \array_diff($mixed_var_ids, $keys);
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) {
return new Clause([], $cond_object_id, $cond_object_id, true);
}
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) {
return new Clause([], $cond_object_id, $cond_object_id, true);
}
}
}
return $c;
},
$if_clauses
)
return $c;
},
$if_clauses
);
$entry_clauses = $context->clauses;

View File

@ -377,7 +377,7 @@ class NamedFunctionCallHandler
if ($first_arg_type->from_docblock) {
if (IssueBuffer::accepts(
new \Psalm\Issue\RedundantCastGivenDocblockType(
'The call to array_values is unnecessary given the docblock type',
'The call to array_values is unnecessary given the list docblock type '.$first_arg_type,
new CodeLocation($statements_analyzer, $function_name)
),
$statements_analyzer->getSuppressedIssues()
@ -387,7 +387,7 @@ class NamedFunctionCallHandler
} else {
if (IssueBuffer::accepts(
new \Psalm\Issue\RedundantCast(
'The call to array_values is unnecessary',
'The call to array_values is unnecessary, '.$first_arg_type.' is already a list',
new CodeLocation($statements_analyzer, $function_name)
),
$statements_analyzer->getSuppressedIssues()

View File

@ -209,7 +209,7 @@ class MatchAnalyzer
}
$all_match_condition = self::convertCondsToConditional(
\array_values($all_conds),
$all_conds,
$match_condition,
$match_condition->getAttributes()
);

View File

@ -83,28 +83,26 @@ class TernaryAnalyzer
}
}
$if_clauses = array_values(
array_map(
$if_clauses = array_map(
/**
* @return \Psalm\Internal\Clause
*/
function (\Psalm\Internal\Clause $c) use ($mixed_var_ids, $cond_id): \Psalm\Internal\Clause {
$keys = array_keys($c->possibilities);
function (\Psalm\Internal\Clause $c) use ($mixed_var_ids, $cond_id): \Psalm\Internal\Clause {
$keys = array_keys($c->possibilities);
$mixed_var_ids = \array_diff($mixed_var_ids, $keys);
$mixed_var_ids = \array_diff($mixed_var_ids, $keys);
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) {
return new \Psalm\Internal\Clause([], $cond_id, $cond_id, true);
}
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) {
return new \Psalm\Internal\Clause([], $cond_id, $cond_id, true);
}
}
}
return $c;
},
$if_clauses
)
return $c;
},
$if_clauses
);
// this will see whether any of the clauses in set A conflict with the clauses in set B

View File

@ -387,7 +387,7 @@ class Pool
}
}
return array_values($terminationMessages);
return $terminationMessages;
}
/**

View File

@ -13,7 +13,6 @@ use Psalm\Report\JsonReport;
use Psalm\Report\ReportOptions;
use Psalm\Tests\Internal\Provider;
use function array_values;
use function file_get_contents;
use function json_decode;
use function ob_end_clean;
@ -815,7 +814,7 @@ echo $a;';
$json_report_options = ProjectAnalyzer::getFileReportOptions([__DIR__ . '/test-report.json'])[0];
$this->assertSame(
array_values($issue_data),
$issue_data,
json_decode(IssueBuffer::getOutput(IssueBuffer::getIssuesData(), $json_report_options), true)
);
}