,ignored_issues?:list,php_version?:string}> */ public function providerValidCodeParse(): iterable { return [ 'twoVarLogicSimple' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' "UK"]; } $arr = []; foreach ([1, 2, 3] as $i) { $row = fetchRow(); if (!isset($arr[$row["c"]])) { $arr[$row["c"]] = 0; } $arr[$row["c"]] = 1; }', 'assertions' => [], 'ignored_issues' => ['MixedArrayOffset'], ], 'moreConvolutedNestedArrayCreation' => [ 'code' => ' "UK"]; } $arr = []; foreach ([1, 2, 3] as $i) { $row = fetchRow(); if (!isset($arr[$row["c"]]["foo"])) { $arr[$row["c"]]["foo"] = 0; } $arr[$row["c"]]["foo"] = 1; }', 'assertions' => [], 'ignored_issues' => ['MixedArrayOffset'], ], 'noParadoxInLoop' => [ 'code' => ' 0; if (!$condition) { foreach ([1, 2] as $value) { if ($condition) { } $condition = true; } } }', ], 'noParadoxInListAssignment' => [ 'code' => ' [ 'code' => ' 0; } function leftover(): bool { $res = get_bool(); if ($res === false) { return true; } $res = get_bool(); if ($res === false) { return false; } return true; }', ], 'noParadoxAfterArrayAppending' => [ 'code' => ' 0) { $errors[] = "unlucky"; } if ($errors) { return false; } return $errors; }', ], 'noParadoxInCatch' => [ 'code' => ' 0) { return ["key" => "value"]; } if (rand() % 3 > 0) { throw new Exception("An exception occurred"); } return null; } function try_catch_check(): array { $arr = null; try { $arr = maybe_returns_array(); if (!$arr) { return []; } } catch (Exception $e) { if (!$arr) { return []; } } return $arr; }', ], 'lotsaTruthyStatements' => [ 'code' => 'a !== null) == true) { return $obj->a; // definitely not null } elseif (!is_null($obj->b) == true) { return $obj->b; } else { throw new \InvalidArgumentException("$obj->a or $obj->b must be set"); } }', ], 'lotsaFalsyStatements' => [ 'code' => 'a === null) == false) { return $obj->a; // definitely not null } elseif (is_null($obj->b) == false) { return $obj->b; } else { throw new \InvalidArgumentException("$obj->a or $obj->b must be set"); } }', ], 'ifGetClass' => [ 'code' => 'foo(); } }', ], 'ifNotEqualsGetClass' => [ 'code' => 'foo(); } }', ], 'nestedCheckWithSingleVarPerLevel' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'foo === null) { $a->foo = "hello"; exit; } if ($a->foo === "somestring") {}', ], 'noParadoxForGetopt' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'bar(); } } }', ], 'callWithNonNullInTernary' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' 2]; echo $array["_a"];', ], 'noMemoryIssueWithLongConditional' => [ 'code' => '= 0x5be && $c <= 0x10b7f)) { return "LTR"; } if ($c <= 0x85e) { if ($c === 0x5be || $c === 0x5c0 || $c === 0x5c3 || $c === 0x5c6 || ($c >= 0x5d0 && $c <= 0x5ea) || ($c >= 0x5f0 && $c <= 0x5f4) || $c === 0x608 || ($c >= 0x712 && $c <= 0x72f) || ($c >= 0x74d && $c <= 0x7a5) || $c === 0x7b1 || ($c >= 0x7c0 && $c <= 0x7ea) || ($c >= 0x7f4 && $c <= 0x7f5) || $c === 0x7fa || ($c >= 0x800 && $c <= 0x815) || $c === 0x81a || $c === 0x824 || $c === 0x828 || ($c >= 0x830 && $c <= 0x83e) || ($c >= 0x840 && $c <= 0x858) || $c === 0x85e ) { return "RTL"; } } elseif ($c === 0x200f) { return "RTL"; } elseif ($c >= 0xfb1d) { if ($c === 0xfb1d || ($c >= 0xfb1f && $c <= 0xfb28) || ($c >= 0xfb2a && $c <= 0xfb36) || ($c >= 0xfb38 && $c <= 0xfb3c) || $c === 0xfb3e || ($c >= 0x10a10 && $c <= 0x10a13) || ($c >= 0x10a15 && $c <= 0x10a17) || ($c >= 0x10a19 && $c <= 0x10a33) || ($c >= 0x10a40 && $c <= 0x10a47) || ($c >= 0x10a50 && $c <= 0x10a58) || ($c >= 0x10a60 && $c <= 0x10a7f) || ($c >= 0x10b00 && $c <= 0x10b35) || ($c >= 0x10b40 && $c <= 0x10b55) || ($c >= 0x10b58 && $c <= 0x10b72) || ($c >= 0x10b78 && $c <= 0x10b7f) ) { return "RTL"; } } return "LTR"; }', 'assertions' => [], 'ignored_issues' => ['MixedInferredReturnType'], ], 'grandParentInstanceofConfusion' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'b && $x->a) { } elseif ($x->c) { $a = true; } if ($x->c) {} if ($a) {} }' ], 'twoVarChangeInElseOnly' => [ 'code' => 'takesA($to); } else { if (!$to) { $to = new A(); $to->takesA($from); } } $from->foo(); $to->foo(); }' ], 'twoVarChangeInElseif' => [ 'code' => 'takesA($to); } elseif (!$to) { $to = new A(); $to->takesA($from); } $from->foo(); $to->foo(); }', ], 'testSimplishThing' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => [], 'php_version' => '8.0', ], 'dependentType' => [ 'code' => 'isValid(); if ($is_valid_a) { $a->foo(); } }' ], 'assignSameName' => [ 'code' => ' [ 'code' => ' [ 'code' => 'a()) { echo $x->b(); } }', 'assertions' => [], 'ignored_issues' => [], 'php_version' => '8.1', ], 'narrowedTypeAfterIdenticalCheckWithOtherType' => [ 'code' => ' [ 'code' => '[] */ private array $dontReport = []; /** * @param class-string $throwable */ public function dontReport(string $throwable): void { $this->dontReport[] = $throwable; } public function shouldReport(Throwable $t): bool { foreach ($this->dontReport as $tc) { if ($t instanceof $tc) { return false; } } return true; } } $h = new Handler(); $h->dontReport(RuntimeException::class); $h->shouldReport(new Exception()); $h->shouldReport(new RuntimeException());' ], 'ThrowableInstanceOfThrowableMayBeTrue' => [ 'code' => ' $class */ final public function map(Throwable $throwable, string $class): ?Throwable { if (! $throwable instanceof $class) { return null; } return $throwable; } }' ], 'combineTwoOrredClausesWithUnnecessaryTerm' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => [], 'php_version' => '8.0', ] ]; } /** * @return iterable,php_version?:string}> */ public function providerInvalidCodeParse(): iterable { return [ 'threeVarLogicWithChange' => [ 'code' => ' 'PossiblyNullArgument', ], 'threeVarLogicWithException' => [ 'code' => ' 'RedundantCondition', ], 'invertedTwoVarLogicNotNestedWithVarChange' => [ 'code' => ' 'NullableReturnStatement', ], 'invertedTwoVarLogicNotNestedWithElseif' => [ 'code' => ' 'NullableReturnStatement', ], 'threeVarLogicWithElseifAndAnd' => [ 'code' => ' 'TypeDoesNotContainType', ], 'twoVarLogicNotNestedWithElseifIncorrectlyReinforcedInIf' => [ 'code' => ' 'RedundantCondition', ], 'repeatedIfStatements' => [ 'code' => ' 'TypeDoesNotContainType', ], 'repeatedConditionals' => [ 'code' => ' 'TypeDoesNotContainType', ], 'repeatedAndConditional' => [ 'code' => ' 'ParadoxicalCondition', ], 'andConditionalAfterOrConditional' => [ 'code' => ' 'TypeDoesNotContainType', ], 'repeatedVarFromOrConditional' => [ 'code' => ' 'TypeDoesNotContainType', ], 'typeDoesntEqualType' => [ 'code' => ' 'RedundantCondition', ], 'stringConcatenationTrackedInvalid' => [ 'code' => ' 2]; echo $array["other"];', 'error_message' => 'InvalidArrayOffset', ], 'redundantTwoVarInElseif' => [ 'code' => ' 'RedundantCondition', ], 'paradoxInTernary' => [ 'code' => ' 'ParadoxicalCondition', ], 'mismatchingChecks' => [ 'code' => ' 'RedundantCondition', ], 'dependentTypeInvalidated' => [ 'code' => 'isValid(); if (rand(0, 1)) { $is_valid_a = false; } if ($is_valid_a) { $a->foo(); } }', 'error_message' => 'PossiblyNullReference', ], 'stillNullAfterNullsafeMethodCall' => [ 'code' => 'a())) { echo $x->b(); } }', 'error_message' => 'NullReference', 'ignored_issues' => [], 'php_version' => '8.1', ], ]; } }