[ ' [ '$b' => 'null|stdClass', ], 'error_levels' => ['RedundantCondition'], ], 'byrefNoRedundantCondition' => [ ' [], 'error_levels' => [ 'RedundantConditionGivenDocblockType', 'DocblockTypeContradiction', ], ], 'assignmentInIf' => [ ' [ ' [], 'error_levels' => [ 'RedundantConditionGivenDocblockType', ], ], 'noRedundantConditionAfterDocblockTypeNullCheck' => [ 'foo) {} break; default: break; } }', 'assertions' => [], 'error_levels' => ['RedundantConditionGivenDocblockType'], ], 'noRedundantConditionTypeReplacementWithDocblock' => [ ' [], 'error_levels' => [ 'DocblockTypeContradiction', ], ], 'noRedundantConditionAfterPossiblyNullCheck' => [ ' [], 'error_levels' => ['PossiblyUndefinedGlobalVariable'], ], 'noRedundantConditionAfterFromDocblockRemoval' => [ 'foo() || $a->bar()) {}', 'assertions' => [], 'error_levels' => [ 'DocblockTypeContradiction', ], ], 'noEmptyUndefinedArrayVar' => [ ' [], 'error_levels' => ['MixedAssignment', 'MixedArrayAccess'], ], 'noComplaintWithIsNumericThenIsEmpty' => [ ' [ ' 0) { throw new RuntimeException("Failed"); } $value = new stdClass(); if (rand() % 2 > 0) { throw new RuntimeException("Failed"); } } catch (Exception $e) { if ($value) { var_export($value); } } if ($value) {} }', ], 'noRedundantConditionInFalseCheck' => [ ' [ 'next) {} } }', ], 'noRedundantConditionComparingBool' => [ ' [ ' [], 'error_levels' => [ 'DocblockTypeContradiction', 'RedundantConditionGivenDocblockType', ], ], 'evaluateArrayCheck' => [ ' false]; while (rand(0, 1) > 0 && !$data["f"]) { $data = ["f" => true]; } }', ], 'mixedArrayAssignment' => [ ' [], 'error_levels' => ['MixedAssignment', 'MixedArrayAccess'], ], 'hardPhpTypeAssertionsOnDocblockType' => [ ' [], 'error_levels' => ['RedundantConditionGivenDocblockType'], ], 'isObjectAssertionOnDocblockType' => [ ' [], 'error_levels' => ['RedundantConditionGivenDocblockType'], ], 'nullToMixedWithNullCheckNoContinue' => [ ' 3) {}', 'assignments' => [], 'error_levels' => [], ], 'replaceFalseTypeWithTrueConditionalOnMixedEquality' => [ ' [], 'error_levels' => ['MixedAssignment', 'MissingReturnType', 'MixedArrayAccess'], ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { return [ 'ifFalse' => [ ' 'RedundantCondition', ], 'ifNotTrue' => [ ' 'RedundantCondition', ], 'ifTrue' => [ ' 'RedundantCondition', ], 'unnecessaryInstanceof' => [ 'fooFoo(); }', 'error_message' => 'RedundantCondition', ], 'failedTypeResolution' => [ ' 'RedundantCondition', ], 'failedTypeResolutionWithDocblock' => [ ' 'RedundantCondition', ], 'typeResolutionFromDocblockAndInstanceof' => [ ' 'RedundantCondition', ], 'typeResolutionRepeatingConditionWithSingleVar' => [ ' 5; if ($a && $a) {}', 'error_message' => 'RedundantCondition', ], 'typeResolutionRepeatingConditionWithVarInMiddle' => [ ' 5; $b = rand(0, 10) > 5; if ($a && $b && $a) {}', 'error_message' => 'RedundantCondition', ], 'typeResolutionIsIntAndIsNumeric' => [ ' 5 ? "hello" : 3; if (is_int($c) && is_numeric($c)) {}', 'error_message' => 'RedundantCondition', ], 'typeResolutionWithInstanceOfAndNotEmpty' => [ ' 5 ? new stdClass : null; if ($x instanceof stdClass && $x) {}', 'error_message' => 'RedundantCondition', ], 'methodWithMeaninglessCheck' => [ 'fooFoo(); } }', 'error_message' => 'RedundantCondition', ], 'SKIPPED-twoVarLogicNotNestedWithElseifNegatedInIf' => [ ' 'RedundantCondition', ], 'refineTypeInMethodCall' => [ ' 'RedundantCondition - src/somefile.php:15', ], 'replaceFalseType' => [ ' 'RedundantCondition', ], 'replaceTrueType' => [ ' 'RedundantCondition', ], ]; } }