[ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' "UK"]; } $arr = []; foreach ([1, 2, 3] as $i) { $row = fetchRow(); if (!isset($arr[$row["c"]])) { $arr[$row["c"]] = 0; } $arr[$row["c"]] = 1; }', 'assertions' => [], 'error_levels' => ['MixedArrayOffset'], ], 'moreConvolutedNestedArrayCreation' => [ ' "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' => [], 'error_levels' => ['MixedArrayOffset'], ], 'noParadoxInLoop' => [ ' 0; if (!$condition) { foreach ([1, 2] as $value) { if ($condition) { } $condition = true; } } }', ], 'noParadoxInListAssignment' => [ ' [ ' 0; } function leftover(): bool { $res = get_bool(); if ($res === false) { return true; } $res = get_bool(); if ($res === false) { return false; } return true; }', ], 'noParadoxAfterArrayAppending' => [ ' 0) { $errors[] = "unlucky"; } if ($errors) { return false; } return $errors; }', ], 'noParadoxInCatch' => [ ' 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' => [ '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' => [ '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' => [ 'foo(); } }', ], 'ifNotEqualsGetClass' => [ 'foo(); } }', ], 'nestedCheckWithSingleVarPerLevel' => [ ' [ ' [ ' [ 'foo === null) { $a->foo = "hello"; exit; } if ($a->foo === "somestring") {}', ], 'propertyFetchAfterNotNullCheckInElseif' => [ ' 5) { } elseif (($a = new A) && $a->foo) {}', ], 'noParadoxForGetopt' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'bar(); } } }', ], 'noParadoxAfterConditionalAssignment' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' 2]; echo $array["_a"];', ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { return [ 'threeVarLogicWithChange' => [ ' 'PossiblyNullArgument', ], 'threeVarLogicWithException' => [ ' 'PossiblyNullArgument', ], 'invertedTwoVarLogicNotNestedWithVarChange' => [ ' 'NullableReturnStatement', ], 'invertedTwoVarLogicNotNestedWithElseif' => [ ' 'NullableReturnStatement', ], 'threeVarLogicWithElseifAndAnd' => [ ' 'ParadoxicalCondition', ], 'twoVarLogicNotNestedWithElseifIncorrectlyReinforcedInIf' => [ ' 'RedundantCondition', ], 'repeatedIfStatements' => [ ' 'TypeDoesNotContainType', ], 'repeatedConditionals' => [ ' 'TypeDoesNotContainType', ], 'repeatedAndConditional' => [ ' 'ParadoxicalCondition', ], 'andConditionalAfterOrConditional' => [ ' 'TypeDoesNotContainType', ], 'repeatedVarFromOrConditional' => [ ' 'TypeDoesNotContainType', ], 'typeDoesntEqualType' => [ ' 'RedundantCondition', ], 'stringConcatenationTrackedInvalid' => [ ' 2]; echo $array["other"];', 'error_message' => 'InvalidArrayOffset', ], ]; } }