,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'whileVar' => [ ' [ '$worked' => 'bool', ], ], 'objectValueWithTwoTypes' => [ 'parent = rand(0, 1) ? new A(): new B(); } } function makeA(): A { return new A(); } $a = makeA(); while ($a instanceof A) { $a = $a->parent; }', 'assertions' => [ '$a' => 'B', ], ], 'objectValueWithInstanceofProperty' => [ 'parent = rand(0, 1) ? new A(): new B(); } } function makeA(): A { return new A(); } $a = makeA(); while ($a->parent instanceof A) { $a = $a->parent; } $b = $a->parent;', 'assertions' => [ '$a' => 'A', '$b' => 'A|B', ], ], 'objectValueNullable' => [ 'parent = rand(0, 1) ? new A(): null; } } function makeA(): A { return new A(); } $a = makeA(); while ($a) { $a = $a->parent; }', 'assertions' => [ '$a' => 'null', ], ], 'objectValueWithAnd' => [ 'parent = rand(0, 1) ? new A(): null; } } function makeA(): A { return new A(); } $a = makeA(); while ($a && rand(0, 10) > 5) { $a = $a->parent; }', 'assertions' => [ '$a' => 'null|A', ], ], 'loopWithNoParadox' => [ ' [ 'bar) {} }', ], 'whileTrueWithBreak' => [ ' [ '$a' => 'string', '$b' => 'int', ], ], 'whileWithNotEmptyCheck' => [ 'a = rand(0, 1) ? new A : null; } } function takesA(A $a): void {} $a = new A(); while ($a) { takesA($a); $a = $a->a; };', 'assertions' => [ '$a' => 'null', ], ], 'whileInstanceOf' => [ 'parent instanceof B) { $a = $a->parent; }', ], 'whileInstanceOfAndNotEmptyCheck' => [ 'parent; $foo = rand(0, 1) ? "hello" : null; if (!$foo) { while ($a instanceof B && !$foo) { $a = $a->parent; $foo = rand(0, 1) ? "hello" : null; } }', ], 'noRedundantConditionAfterArrayAssignment' => [ ' false]; while (!$data["a"]) { if (rand() % 2 > 0) { $data = ["a" => true]; } }', ], 'additionSubtractionOps' => [ ' [ ' [ 'foo; } } }', ], 'shouldBeFine' => [ 'bar instanceof A) ) { if (!$node instanceof C) { $node = $node->foo; } else { $node = $node->bar; } } }', ], 'comparisonAfterContinue' => [ ' [ ' 0) {} echo $i === 0;', ], ]; } /** * @return iterable */ public function providerInvalidCodeParse() { return [ 'whileTrueNoBreak' => [ ' 'UndefinedGlobalVariable', ], 'invalidateByRefAssignmentWithRedundantCondition' => [ ' 'RedundantCondition', ], ]; } }