1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

fix bugs in tests

This commit is contained in:
kkmuffme 2024-01-12 23:37:45 +01:00
parent 19b1a33a20
commit 93dc2219e0
19 changed files with 121 additions and 42 deletions

View File

@ -663,7 +663,7 @@ class ArrayAccessTest extends TestCase
$x = $d[0];', $x = $d[0];',
'assertions' => [ 'assertions' => [
'$x===' => '"a"|null', '$x===' => '\'a\'',
], ],
'ignored_issues' => ['PossiblyUndefinedArrayOffset'], 'ignored_issues' => ['PossiblyUndefinedArrayOffset'],
], ],
@ -1349,7 +1349,7 @@ class ArrayAccessTest extends TestCase
echo $a[new Foo];', echo $a[new Foo];',
'error_message' => 'InvalidArrayOffset', 'error_message' => 'InvalidArrayOffset',
], ],
'possiblyUndefinedIntArrayOffet' => [ 'possiblyUndefinedIntArrayOffset' => [
'code' => '<?php 'code' => '<?php
/** @var array{0?:string} */ /** @var array{0?:string} */
$entry = ["a"]; $entry = ["a"];
@ -1357,7 +1357,7 @@ class ArrayAccessTest extends TestCase
[$elt] = $entry;', [$elt] = $entry;',
'error_message' => 'PossiblyUndefinedArrayOffset', 'error_message' => 'PossiblyUndefinedArrayOffset',
], ],
'possiblyUndefinedStringArrayOffet' => [ 'possiblyUndefinedStringArrayOffset' => [
'code' => '<?php 'code' => '<?php
/** @var array{a?:string} */ /** @var array{a?:string} */
$entry = ["a"]; $entry = ["a"];
@ -1542,6 +1542,19 @@ class ArrayAccessTest extends TestCase
avg(["a" => 0.5, "b" => 1.5, "c" => new Exception()]);', avg(["a" => 0.5, "b" => 1.5, "c" => new Exception()]);',
'error_message' => 'InvalidArgument', 'error_message' => 'InvalidArgument',
], ],
'possiblyUndefinedArrayOffsetKeyedArray' => [
'code' => '<?php
$d = [];
if (!rand(0,1)) {
$d[0] = "a";
}
$x = $d[0];
// should not report TypeDoesNotContainNull
if ($x === null) {}',
'error_message' => 'PossiblyUndefinedArrayOffset',
],
]; ];
} }
} }

View File

@ -1937,7 +1937,7 @@ class FunctionCallTest extends TestCase
'strposAllowDictionary' => [ 'strposAllowDictionary' => [
'code' => '<?php 'code' => '<?php
function sayHello(string $format): void { function sayHello(string $format): void {
if (strpos("abcdefghijklmno", $format)) {} if (strpos("abcdefghijklmno", $format) !== false) {}
}', }',
], ],
'curlInitIsResourceAllowedIn7x' => [ 'curlInitIsResourceAllowedIn7x' => [
@ -2138,7 +2138,7 @@ class FunctionCallTest extends TestCase
'strposFirstParamAllowClassString' => [ 'strposFirstParamAllowClassString' => [
'code' => '<?php 'code' => '<?php
function sayHello(string $needle): void { function sayHello(string $needle): void {
if (strpos(DateTime::class, $needle)) {} if (strpos(DateTime::class, $needle) !== false) {}
}', }',
], ],
'mb_strtolowerProducesStringWithSecondArgument' => [ 'mb_strtolowerProducesStringWithSecondArgument' => [

View File

@ -300,7 +300,7 @@ class ImmutableAnnotationTest extends TestCase
$dto = new DTO("BOOM!"); $dto = new DTO("BOOM!");
if ($dto->getError()) { if ($dto->getError() !== null) {
takesString($dto->getError()); takesString($dto->getError());
}', }',
], ],

View File

@ -138,6 +138,7 @@ class JsonOutputTest extends TestCase
], ],
'singleIssueForTypeDifference' => [ 'singleIssueForTypeDifference' => [
'code' => '<?php 'code' => '<?php
/** @psalm-suppress RiskyTruthyFalsyComparison */
function fooFoo(?string $a, ?string $b): void { function fooFoo(?string $a, ?string $b): void {
if ($a || $b) { if ($a || $b) {
if ($a || $b) {} if ($a || $b) {}
@ -145,7 +146,7 @@ class JsonOutputTest extends TestCase
}', }',
'error_count' => 1, 'error_count' => 1,
'message' => 'Operand of type non-falsy-string is always truthy', 'message' => 'Operand of type non-falsy-string is always truthy',
'line' => 4, 'line' => 5,
'error' => '$b', 'error' => '$b',
], ],
]; ];

View File

@ -245,7 +245,7 @@ class DoTest extends TestCase
$c = null; $c = null;
do { do {
if (!$c) { if ($c === null || $c === "" || $c === "0") {
foo($c); foo($c);
} else { } else {
bar($c); bar($c);

View File

@ -155,7 +155,7 @@ class WhileTest extends TestCase
} }
while ($a = foo()) { while ($a = foo()) {
if ($a->bar) {} if ($a->bar !== null) {}
}', }',
], ],
'whileTrueWithBreak' => [ 'whileTrueWithBreak' => [
@ -271,7 +271,7 @@ class WhileTest extends TestCase
$c = null; $c = null;
while (rand(0, 1)) { while (rand(0, 1)) {
if (!$c) { if ($c === null || $c === "" || $c === "0") {
foo($c); foo($c);
} else { } else {
bar($c); bar($c);

View File

@ -149,7 +149,7 @@ class MethodCallTest extends TestCase
$obj = new SomeClass(); $obj = new SomeClass();
if ($obj->getInt()) { if ($obj->getInt() !== null) {
printInt($obj->getInt()); printInt($obj->getInt());
}', }',
); );
@ -185,7 +185,7 @@ class MethodCallTest extends TestCase
$obj = new SomeClass(); $obj = new SomeClass();
if ($obj->getInt()) { if ($obj->getInt() !== null) {
printInt($obj->getInt()); printInt($obj->getInt());
}', }',
); );
@ -936,7 +936,7 @@ class MethodCallTest extends TestCase
$a = new A(); $a = new A();
if ($a->getA()) { if ($a->getA() !== null) {
echo strlen($a->getA()); echo strlen($a->getA());
}', }',
], ],
@ -1007,7 +1007,7 @@ class MethodCallTest extends TestCase
$obj = new SomeClass(); $obj = new SomeClass();
if ($obj->getInt()) { if ($obj->getInt() !== null) {
printInt($obj->getInt()); printInt($obj->getInt());
}', }',
], ],
@ -1031,7 +1031,7 @@ class MethodCallTest extends TestCase
$obj = new SomeClass(); $obj = new SomeClass();
if ($obj->getInt()) { if ($obj->getInt() !== null) {
printInt($obj->getInt()); printInt($obj->getInt());
}', }',
], ],
@ -1631,7 +1631,7 @@ class MethodCallTest extends TestCase
} }
function foo(A $a) : void { function foo(A $a) : void {
if ($a->getA()) { if ($a->getA() !== null) {
echo strlen($a->getA()); echo strlen($a->getA());
} }
} }
@ -1697,7 +1697,7 @@ class MethodCallTest extends TestCase
$obj = new SomeClass(); $obj = new SomeClass();
if ($obj->getInt()) { if ($obj->getInt() !== null) {
printInt($obj->getInt()); printInt($obj->getInt());
}', }',
'error_message' => 'PossiblyNullArgument', 'error_message' => 'PossiblyNullArgument',

View File

@ -311,7 +311,7 @@ class MethodSignatureTest extends TestCase
class B extends A { class B extends A {
public function foo(?string $s): string { public function foo(?string $s): string {
return $s ?: "hello"; return $s !== null ? $s : "hello";
} }
} }
@ -327,7 +327,7 @@ class MethodSignatureTest extends TestCase
class B extends A { class B extends A {
public function foo(string $s = null): string { public function foo(string $s = null): string {
return $s ?: "hello"; return $s !== null ? $s : "hello";
} }
} }
@ -1044,7 +1044,7 @@ class MethodSignatureTest extends TestCase
'code' => '<?php 'code' => '<?php
class A { class A {
public function foo(?string $s): string { public function foo(?string $s): string {
return $s ?: "hello"; return $s !== null ? $s : "hello";
} }
} }

View File

@ -183,7 +183,7 @@ class PropertyTypeTest extends TestCase
} }
function testX(X $x): void { function testX(X $x): void {
if ($x->getX()) { if (is_int($x->getX())) {
XCollector::modify(); XCollector::modify();
if ($x->getX() === null) {} if ($x->getX() === null) {}
} }
@ -221,7 +221,7 @@ class PropertyTypeTest extends TestCase
} }
function testX(X $x): void { function testX(X $x): void {
if ($x->getX()) { if ($x->getX() !== null) {
XCollector::modify(); XCollector::modify();
if ($x->getX() === null) {} if ($x->getX() === null) {}
} }
@ -255,7 +255,7 @@ class PropertyTypeTest extends TestCase
} }
function testX(X $x): void { function testX(X $x): void {
if ($x->x) { if ($x->x !== null) {
XCollector::modify(); XCollector::modify();
if ($x->x === null) {} if ($x->x === null) {}
} }
@ -686,6 +686,8 @@ class PropertyTypeTest extends TestCase
} }
echo substr($a->aa, 1);', echo substr($a->aa, 1);',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'nullableStaticPropertyWithIfCheck' => [ 'nullableStaticPropertyWithIfCheck' => [
'code' => '<?php 'code' => '<?php

View File

@ -100,6 +100,8 @@ class ReturnTypeTest extends TestCase
return $str; return $str;
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'returnTypeNotEmptyCheckInElseIf' => [ 'returnTypeNotEmptyCheckInElseIf' => [
'code' => '<?php 'code' => '<?php
@ -118,6 +120,8 @@ class ReturnTypeTest extends TestCase
return $str; return $str;
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'returnTypeNotEmptyCheckInElse' => [ 'returnTypeNotEmptyCheckInElse' => [
'code' => '<?php 'code' => '<?php
@ -136,6 +140,8 @@ class ReturnTypeTest extends TestCase
return $str; return $str;
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'returnTypeAfterIf' => [ 'returnTypeAfterIf' => [
'code' => '<?php 'code' => '<?php

View File

@ -547,7 +547,7 @@ class SwitchTypeTest extends TestCase
return "float"; return "float";
} }
if ($fq_const_name && isset($predefined_constants[$fq_const_name])) { if ($fq_const_name !== null && isset($predefined_constants[$fq_const_name])) {
return "mixed"; return "mixed";
} }

View File

@ -2878,6 +2878,8 @@ class ClassTemplateTest extends TestCase
): void { ): void {
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'noCrashTemplateInsideGenerator' => [ 'noCrashTemplateInsideGenerator' => [
'code' => '<?php 'code' => '<?php

View File

@ -298,6 +298,8 @@ class AssignmentInConditionalTest extends TestCase
return $pos; return $pos;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'assignmentInIf' => [ 'assignmentInIf' => [
'code' => '<?php 'code' => '<?php
@ -416,7 +418,7 @@ class AssignmentInConditionalTest extends TestCase
} }
if (rand(0, 10) > 5) { if (rand(0, 10) > 5) {
} elseif (($a = rand(0, 1) ? new A : null) && $a->foo) {}', } elseif (($a = rand(0, 1) ? new A : null) && is_string($a->foo)) {}',
], ],
'noParadoxAfterConditionalAssignment' => [ 'noParadoxAfterConditionalAssignment' => [
'code' => '<?php 'code' => '<?php
@ -485,7 +487,7 @@ class AssignmentInConditionalTest extends TestCase
return "b"; return "b";
}', }',
'error_message' => 'InvalidReturnStatement', 'error_message' => 'InvalidReturnStatement',
'ignored_issues' => [], 'ignored_issues' => ['RiskyTruthyFalsyComparison'],
'php_version' => '8.0', 'php_version' => '8.0',
], ],
'assignmentInBranchOfAndReferencedAfterIf' => [ 'assignmentInBranchOfAndReferencedAfterIf' => [

View File

@ -594,6 +594,8 @@ class ConditionalTest extends TestCase
} }
return false; return false;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'numericStringAssertion' => [ 'numericStringAssertion' => [
'code' => '<?php 'code' => '<?php
@ -1943,6 +1945,8 @@ class ConditionalTest extends TestCase
if ($a && strlen($a) > 5) {} if ($a && strlen($a) > 5) {}
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'arrayUnionTypeSwitching' => [ 'arrayUnionTypeSwitching' => [
'code' => '<?php 'code' => '<?php
@ -1958,6 +1962,8 @@ class ConditionalTest extends TestCase
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'propertySetOnElementInConditional' => [ 'propertySetOnElementInConditional' => [
'code' => '<?php 'code' => '<?php
@ -2165,6 +2171,8 @@ class ConditionalTest extends TestCase
echo $valuePath; echo $valuePath;
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'issetAssertionOnStaticProperty' => [ 'issetAssertionOnStaticProperty' => [
'code' => '<?php 'code' => '<?php
@ -2509,6 +2517,8 @@ class ConditionalTest extends TestCase
return [$type]; return [$type];
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'nonEmptyStringAfterLiteralCheck' => [ 'nonEmptyStringAfterLiteralCheck' => [
'code' => '<?php 'code' => '<?php

View File

@ -114,6 +114,8 @@ class EmptyTest extends TestCase
return "an exception"; return "an exception";
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'emptyExceptionReconciliationAfterIf' => [ 'emptyExceptionReconciliationAfterIf' => [
'code' => '<?php 'code' => '<?php
@ -175,6 +177,8 @@ class EmptyTest extends TestCase
foreach ($arr as $item) { foreach ($arr as $item) {
if (empty($item["hide"]) || $item["hide"] === 3) {} if (empty($item["hide"]) || $item["hide"] === 3) {}
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'alwaysBoolResult' => [ 'alwaysBoolResult' => [
'code' => '<?php 'code' => '<?php
@ -219,7 +223,7 @@ class EmptyTest extends TestCase
if (empty($scopes)){} if (empty($scopes)){}
}', }',
'assertions' => [], 'assertions' => [],
'ignored_issues' => ['MixedAssignment', 'MissingParamType', 'MixedArgument'], 'ignored_issues' => ['MixedAssignment', 'MissingParamType', 'MixedArgument', 'RiskyTruthyFalsyComparison'],
], ],
'multipleEmptiesInCondition' => [ 'multipleEmptiesInCondition' => [
'code' => '<?php 'code' => '<?php
@ -389,6 +393,8 @@ class EmptyTest extends TestCase
echo $arr["a"]; echo $arr["a"];
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'reconcileEmptyTwiceWithoutReturn' => [ 'reconcileEmptyTwiceWithoutReturn' => [
'code' => '<?php 'code' => '<?php

View File

@ -409,7 +409,7 @@ class IssetTest extends TestCase
$a = isset($_GET["a"]) ? $_GET["a"] : ""; $a = isset($_GET["a"]) ? $_GET["a"] : "";
if ($a) {}', if ($a) {}',
'assertions' => [], 'assertions' => [],
'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess', 'RiskyTruthyFalsyComparison'],
], ],
'mixedArrayIssetGetStringVar' => [ 'mixedArrayIssetGetStringVar' => [
'code' => '<?php 'code' => '<?php

View File

@ -66,6 +66,10 @@ class RedundantConditionTest extends TestCase
} }
return $x; return $x;
}', }',
'assertions' => [],
'ignored_issues' => [
'RiskyTruthyFalsyComparison',
],
], ],
'noRedundantConditionAfterAssignment' => [ 'noRedundantConditionAfterAssignment' => [
'code' => '<?php 'code' => '<?php
@ -99,7 +103,7 @@ class RedundantConditionTest extends TestCase
switch (get_class($i)) { switch (get_class($i)) {
case A::class: case A::class:
if ($i->foo) {} if ($i->foo !== null) {}
break; break;
default: default:
@ -180,7 +184,7 @@ class RedundantConditionTest extends TestCase
} }
if ($a) {}', if ($a) {}',
'assertions' => [], 'assertions' => [],
'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess', 'RiskyTruthyFalsyComparison'],
], ],
'noComplaintWithIsNumericThenIsEmpty' => [ 'noComplaintWithIsNumericThenIsEmpty' => [
'code' => '<?php 'code' => '<?php
@ -377,7 +381,7 @@ class RedundantConditionTest extends TestCase
/** @psalm-suppress PossiblyUndefinedGlobalVariable */ /** @psalm-suppress PossiblyUndefinedGlobalVariable */
$option = $options["option"] ?? false; $option = $options["option"] ?? false;
if ($option) {}', if ($option !== false) {}',
'assertions' => [], 'assertions' => [],
'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'],
], ],
@ -539,7 +543,7 @@ class RedundantConditionTest extends TestCase
exit; exit;
} }
if ($i) {}', if ($i !== array() && $i !== "" && $i !== "0") {}',
], ],
'emptyWithoutKnowingArrayType' => [ 'emptyWithoutKnowingArrayType' => [
'code' => '<?php 'code' => '<?php
@ -825,7 +829,7 @@ class RedundantConditionTest extends TestCase
'code' => '<?php 'code' => '<?php
function test(string|int|float|bool $value): bool { function test(string|int|float|bool $value): bool {
if (is_numeric($value) || $value === true) { if (is_numeric($value) || $value === true) {
if ($value) { if ($value === true || (int) $value !== 0) {
return true; return true;
} }
} }
@ -1068,6 +1072,7 @@ class RedundantConditionTest extends TestCase
return $a; return $a;
}', }',
'error_message' => 'RedundantCondition', 'error_message' => 'RedundantCondition',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'refineTypeInMethodCall' => [ 'refineTypeInMethodCall' => [
'code' => '<?php 'code' => '<?php

View File

@ -53,6 +53,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'twoVarLogicNotNestedWithAllPathsReturning' => [ 'twoVarLogicNotNestedWithAllPathsReturning' => [
'code' => '<?php 'code' => '<?php
@ -67,6 +69,8 @@ class TypeAlgebraTest extends TestCase
} }
} }
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'twoVarLogicNotNestedWithAssignmentBeforeReturn' => [ 'twoVarLogicNotNestedWithAssignmentBeforeReturn' => [
'code' => '<?php 'code' => '<?php
@ -83,6 +87,8 @@ class TypeAlgebraTest extends TestCase
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'invertedTwoVarLogicNotNested' => [ 'invertedTwoVarLogicNotNested' => [
'code' => '<?php 'code' => '<?php
@ -96,6 +102,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'invertedTwoVarLogicNotNestedWithAssignmentBeforeReturn' => [ 'invertedTwoVarLogicNotNestedWithAssignmentBeforeReturn' => [
'code' => '<?php 'code' => '<?php
@ -110,6 +118,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'twoVarLogicNotNestedWithElseifAndNoNegations' => [ 'twoVarLogicNotNestedWithElseifAndNoNegations' => [
'code' => '<?php 'code' => '<?php
@ -125,6 +135,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'threeVarLogicNotNestedWithNoRedefinitionsWithClasses' => [ 'threeVarLogicNotNestedWithNoRedefinitionsWithClasses' => [
'code' => '<?php 'code' => '<?php
@ -163,6 +175,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'threeVarLogicNotNestedAndOrWithNoRedefinitions' => [ 'threeVarLogicNotNestedAndOrWithNoRedefinitions' => [
'code' => '<?php 'code' => '<?php
@ -179,6 +193,8 @@ class TypeAlgebraTest extends TestCase
if (!$a) return $b; if (!$a) return $b;
return $a; return $a;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'twoVarLogicNotNestedWithElseifCorrectlyNegatedInElseIf' => [ 'twoVarLogicNotNestedWithElseifCorrectlyNegatedInElseIf' => [
'code' => '<?php 'code' => '<?php
@ -415,6 +431,8 @@ class TypeAlgebraTest extends TestCase
} }
return $arr; return $arr;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'lotsaTruthyStatements' => [ 'lotsaTruthyStatements' => [
'code' => '<?php 'code' => '<?php
@ -998,6 +1016,8 @@ class TypeAlgebraTest extends TestCase
return $b; return $b;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'cancelOutDifferentStatement' => [ 'cancelOutDifferentStatement' => [
'code' => '<?php 'code' => '<?php
@ -1012,6 +1032,8 @@ class TypeAlgebraTest extends TestCase
return $b; return $b;
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'moreChecks' => [ 'moreChecks' => [
'code' => '<?php 'code' => '<?php
@ -1186,6 +1208,8 @@ class TypeAlgebraTest extends TestCase
if ($foo === null) {} if ($foo === null) {}
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'compareToIntInsideIfCNF' => [ 'compareToIntInsideIfCNF' => [
'code' => '<?php 'code' => '<?php
@ -1198,6 +1222,8 @@ class TypeAlgebraTest extends TestCase
if ($foo === null) {} if ($foo === null) {}
}', }',
'assertions' => [],
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'ternaryAssertionOnBool' => [ 'ternaryAssertionOnBool' => [
'code' => '<?php 'code' => '<?php
@ -1304,6 +1330,7 @@ class TypeAlgebraTest extends TestCase
return $a; return $a;
}', }',
'error_message' => 'NullableReturnStatement', 'error_message' => 'NullableReturnStatement',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'invertedTwoVarLogicNotNestedWithElseif' => [ 'invertedTwoVarLogicNotNestedWithElseif' => [
'code' => '<?php 'code' => '<?php
@ -1320,6 +1347,7 @@ class TypeAlgebraTest extends TestCase
return $a; return $a;
}', }',
'error_message' => 'NullableReturnStatement', 'error_message' => 'NullableReturnStatement',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'threeVarLogicWithElseifAndAnd' => [ 'threeVarLogicWithElseifAndAnd' => [
'code' => '<?php 'code' => '<?php
@ -1337,6 +1365,7 @@ class TypeAlgebraTest extends TestCase
return $a; return $a;
}', }',
'error_message' => 'TypeDoesNotContainType', 'error_message' => 'TypeDoesNotContainType',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'twoVarLogicNotNestedWithElseifIncorrectlyReinforcedInIf' => [ 'twoVarLogicNotNestedWithElseifIncorrectlyReinforcedInIf' => [
'code' => '<?php 'code' => '<?php
@ -1353,6 +1382,7 @@ class TypeAlgebraTest extends TestCase
return $a; return $a;
}', }',
'error_message' => 'RedundantCondition', 'error_message' => 'RedundantCondition',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'repeatedIfStatements' => [ 'repeatedIfStatements' => [
'code' => '<?php 'code' => '<?php
@ -1367,6 +1397,7 @@ class TypeAlgebraTest extends TestCase
} }
}', }',
'error_message' => 'TypeDoesNotContainType', 'error_message' => 'TypeDoesNotContainType',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'repeatedConditionals' => [ 'repeatedConditionals' => [
'code' => '<?php 'code' => '<?php
@ -1459,6 +1490,7 @@ class TypeAlgebraTest extends TestCase
} }
}', }',
'error_message' => 'RedundantCondition', 'error_message' => 'RedundantCondition',
'ignored_issues' => ['RiskyTruthyFalsyComparison'],
], ],
'dependentTypeInvalidated' => [ 'dependentTypeInvalidated' => [
'code' => '<?php 'code' => '<?php

View File

@ -102,7 +102,7 @@ class UnusedVariableTest extends TestCase
function foo(array $arr) : void { function foo(array $arr) : void {
$a = null; $a = null;
foreach ($arr as $a) { } foreach ($arr as $a) { }
if ($a) {} if ($a !== null) {}
}', }',
], ],
'definedInSecondBranchOfCondition' => [ 'definedInSecondBranchOfCondition' => [
@ -128,10 +128,10 @@ class UnusedVariableTest extends TestCase
'dummyByRefVar' => [ 'dummyByRefVar' => [
'code' => '<?php 'code' => '<?php
function foo(string &$a = null, string $b = null): void { function foo(string &$a = null, string $b = null): void {
if ($a) { if ($a !== null) {
echo $a; echo $a;
} }
if ($b) { if ($b !== null) {
echo $b; echo $b;
} }
} }
@ -327,7 +327,7 @@ class UnusedVariableTest extends TestCase
echo $e->getMessage(); echo $e->getMessage();
} }
if ($s) {} if ($s !== null) {}
}', }',
], ],
'throwWithMessageCallAndAssignmentInCatchAndReference' => [ 'throwWithMessageCallAndAssignmentInCatchAndReference' => [
@ -940,7 +940,7 @@ class UnusedVariableTest extends TestCase
if ($foo) {} if ($foo) {}
} catch (Exception $e) {} } catch (Exception $e) {}
if ($foo) {}', if ($foo !== false && $foo !== 0) {}',
], ],
'useTryAssignedVariableInsideFinally' => [ 'useTryAssignedVariableInsideFinally' => [
'code' => '<?php 'code' => '<?php
@ -1953,7 +1953,7 @@ class UnusedVariableTest extends TestCase
$arr = str_getcsv($value); $arr = str_getcsv($value);
foreach ($arr as &$element) { foreach ($arr as &$element) {
$element = $element ?: "foo"; $element = $element !== null ?: "foo";
} }
return $arr; return $arr;
@ -2337,7 +2337,7 @@ class UnusedVariableTest extends TestCase
} }
}', }',
'assertions' => [], 'assertions' => [],
'ignored_issues' => [], 'ignored_issues' => ['RiskyTruthyFalsyComparison'],
'php_version' => '8.0', 'php_version' => '8.0',
], ],
'concatWithUnknownProperty' => [ 'concatWithUnknownProperty' => [
@ -3165,7 +3165,7 @@ class UnusedVariableTest extends TestCase
$user = $user_id; $user = $user_id;
} }
if ($user) { if ($user !== null && $user !== 0) {
$a = 0; $a = 0;
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
$a += $i; $a += $i;
@ -3185,7 +3185,7 @@ class UnusedVariableTest extends TestCase
$user = $user_id; $user = $user_id;
} }
if ($user) { if ($user !== null && $user !== 0) {
$a = 0; $a = 0;
foreach ([1, 2, 3] as $i) { foreach ([1, 2, 3] as $i) {
$a += $i; $a += $i;