mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #1737 - treat !isset($x, $y) properly
This commit is contained in:
parent
778b95d335
commit
d34c1a94db
@ -171,6 +171,39 @@ class Algebra
|
||||
$inside_negation
|
||||
);
|
||||
}
|
||||
|
||||
if ($conditional->expr instanceof PhpParser\Node\Expr\Isset_) {
|
||||
AssertionFinder::scrapeAssertions(
|
||||
$conditional->expr,
|
||||
$this_class_name,
|
||||
$source,
|
||||
$codebase,
|
||||
$inside_negation
|
||||
);
|
||||
|
||||
if (isset($conditional->expr->assertions) && $conditional->expr->assertions) {
|
||||
$assertions = $conditional->expr->assertions;
|
||||
|
||||
$clauses = [];
|
||||
|
||||
foreach ($assertions as $var => $anded_types) {
|
||||
foreach ($anded_types as $orred_types) {
|
||||
$clauses[] = new Clause(
|
||||
[$var => $orred_types],
|
||||
false,
|
||||
true,
|
||||
$orred_types[0][0] === '='
|
||||
|| $orred_types[0][0] === '~'
|
||||
|| (strlen($orred_types[0]) > 1
|
||||
&& ($orred_types[0][1] === '='
|
||||
|| $orred_types[0][1] === '~'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return self::negateFormula($clauses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical) {
|
||||
|
@ -515,6 +515,43 @@ class IssetTest extends TestCase
|
||||
'<?php
|
||||
$a = $_SESSION ?? [];',
|
||||
],
|
||||
'issetSeparateNegated' => [
|
||||
'<?php
|
||||
function foo(?string $a, ?string $b): string {
|
||||
if (!isset($a) || !isset($b)) {
|
||||
return "";
|
||||
}
|
||||
return $a . $b;
|
||||
}',
|
||||
],
|
||||
'issetMultipleNegated' => [
|
||||
'<?php
|
||||
function foo(?string $a, ?string $b): string {
|
||||
if (!isset($a, $b)) {
|
||||
return "";
|
||||
}
|
||||
return $a . $b;
|
||||
}',
|
||||
],
|
||||
'issetMultipleNegatedWithExtraClause' => [
|
||||
'<?php
|
||||
function foo(?string $a, ?string $b): string {
|
||||
if (!(isset($a, $b) && rand(0, 1))) {
|
||||
return "";
|
||||
}
|
||||
return $a . $b;
|
||||
}',
|
||||
],
|
||||
'issetMultipleNotNegated' => [
|
||||
'<?php
|
||||
function foo(?string $a, ?string $b): string {
|
||||
if (isset($a, $b)) {
|
||||
return $a . $b;
|
||||
}
|
||||
|
||||
return "";
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user