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

Fix isset check

This commit is contained in:
Matthew Brown 2018-05-30 20:54:03 -04:00
parent eb10b15cfc
commit 33a38113f3
5 changed files with 48 additions and 4 deletions

View File

@ -180,7 +180,7 @@ class IfChecker
$if_context->inside_conditional = false;
$mixed_var_ids = [];
$mixed_var_ids = ['$_GET', '$_POST'];
foreach ($if_context->vars_in_scope as $var_id => $type) {
if ($type->isMixed()) {
@ -871,7 +871,7 @@ class IfChecker
$elseif_context->inside_conditional = false;
$mixed_var_ids = [];
$mixed_var_ids = ['$_GET', '$_POST'];
foreach ($elseif_context->vars_in_scope as $var_id => $type) {
if ($type->isMixed()) {

View File

@ -283,7 +283,7 @@ class BinaryOpChecker
$statements_checker
);
$mixed_var_ids = [];
$mixed_var_ids = ['$_GET', '$_POST'];
foreach ($context->vars_in_scope as $var_id => $type) {
if ($type->isMixed()) {

View File

@ -45,6 +45,43 @@ class TernaryChecker
$statements_checker
);
$mixed_var_ids = ['$_GET', '$_POST'];
foreach ($context->vars_in_scope as $var_id => $type) {
if ($type->isMixed()) {
$mixed_var_ids[] = $var_id;
}
}
foreach ($context->vars_possibly_in_scope as $var_id => $_) {
if (!isset($context->vars_in_scope[$var_id])) {
$mixed_var_ids[] = $var_id;
}
}
$if_clauses = array_values(
array_map(
/**
* @return \Psalm\Clause
*/
function (\Psalm\Clause $c) use ($mixed_var_ids) {
$keys = array_keys($c->possibilities);
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) {
return new \Psalm\Clause([], true);
}
}
}
return $c;
},
$if_clauses
)
);
$ternary_clauses = Algebra::simplifyCNF(array_merge($context->clauses, $if_clauses));
$negated_clauses = Algebra::negateFormula($if_clauses);

View File

@ -1055,7 +1055,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource
return $context->vars_in_scope[$const_name];
}
$file_path = $statements_checker->getFilePath();
$file_path = $statements_checker->getRootFilePath();
$project_checker = $statements_checker->getFileChecker()->project_checker;
$file_storage_provider = $project_checker->file_storage_provider;

View File

@ -334,6 +334,13 @@ class IssetTest extends TestCase
if ($arr[$k][0]) {}
}',
],
'mixedArrayIsset' => [
'<?php
$a = isset($_GET["a"]) ? $_GET["a"] : "";
if ($a) {}',
'assertions' => [],
'error_levels' => ['MixedAssignment', 'MixedArrayAccess'],
],
];
}