[ ' [ ' [ ' [ ' [ ' [ '$worked' => 'bool', ], ], 'doWhileVar' => [ ' [ '$worked' => 'bool', ], ], 'doWhileVarAndBreak' => [ ' [ 'child = rand(0, 1) ? new A() : new B(); } } function makeA() : A { return new A(); } $a = makeA(); while ($a instanceof A) { $a = $a->child; }', 'assertions' => [ '$a' => 'B', ], ], 'secondLoopWithNotNullCheck' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ '$b' => 'bool', ], ], 'assignInsideForeachWithBreak' => [ ' [ '$b' => 'bool', ], ], 'nullCheckInsideForeachWithContinue' => [ ' */ public static function loadMultiple() { return [new A, null]; } /** @return void */ public function barBar() { } } foreach (A::loadMultiple() as $a) { if ($a === null) { continue; } $a->barBar(); }', ], 'loopWithArrayKey' => [ ' $value) { if (isset($merged[$key])) { $merged[$key] = array_merge($merged[$key], $value); } else { $merged[$key] = $value; } } } return $merged; }', ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { return [ 'possiblyUndefinedArrayInForeach' => [ ' 'PossiblyUndefinedVariable - src/somefile.php:3 - Possibly undefined variable ' . '$array, first seen on line 3', ], 'possiblyUndefinedArrayInWhileAndForeach' => [ ' 'PossiblyUndefinedVariable - src/somefile.php:4 - Possibly undefined variable ' . '$array, first seen on line 4', ], 'possiblyUndefinedVariableInForeach' => [ ' 'PossiblyUndefinedVariable - src/somefile.php:6 - Possibly undefined variable ' . '$car, first seen on line 3', ], 'possibleUndefinedVariableInForeachAndIf' => [ ' 'PossiblyUndefinedVariable - src/somefile.php:9 - Possibly undefined variable $a, ' . 'first seen on line 4', ], 'implicitFourthLoopWithBadReturnType' => [ ' 'InvalidReturnType', ], 'possiblyNullCheckInsideForeachWithNoLeaveStatement' => [ ' */ public static function loadMultiple() { return [new A, null]; } /** @return void */ public function barBar() { } } foreach (A::loadMultiple() as $a) { if ($a === null) { // do nothing } $a->barBar(); }', 'error_message' => 'PossiblyNullReference', ], ]; } }