[ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' 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") {}', ], 'propertyFetchAfterNotNullCheck' => [ ' 5) { } elseif (($a = new A) && $a->foo) {}', ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { return [ 'threeVarLogicWithChange' => [ ' 'PossiblyNullArgument', ], 'threeVarLogicWithException' => [ ' 'PossiblyNullArgument', ], 'invertedTwoVarLogicNotNestedWithVarChange' => [ ' 'InvalidReturnType', ], 'invertedTwoVarLogicNotNestedWithElseif' => [ ' 'InvalidReturnType', ], 'threeVarLogicWithElseifAndAnd' => [ ' 'InvalidReturnType', ], 'twoVarLogicNotNestedWithElseifIncorrectlyReinforcedInIf' => [ ' 'InvalidReturnType', ], 'repeatedIfStatements' => [ ' 'ParadoxicalCondition', ], 'repeatedConditionals' => [ ' 'ParadoxicalCondition', ], 'repeatedAndConditional' => [ ' 'ParadoxicalCondition', ], 'andConditionalAfterOrConditional' => [ ' 'ParadoxicalCondition', ], 'repeatedVarFromOrConditional' => [ ' 'ParadoxicalCondition', ], ]; } }