,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' => 'A|null', ], ], '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;', ], 'noRedundantConditionOnAddedSubtractedInLoop' => [ ' [ ' [ ' [ ' $fields */ function changeVarAfterUse(array $values, array $fields): void { foreach ($fields as $field) { if (!isset($values[$field])) { continue; } /** @psalm-suppress MixedAssignment */ $value = $values[$field]; /** @psalm-suppress MixedArgument */ takesString($value); $values[$field] = null; } }', ], 'invalidateWhileAssertion' => [ ' [ ' [ ']+>)|([^<]+)+/isU\'; // pour chaque element trouve : $str = ""; $offset = 0; while (preg_match($reg, $content, $parse, PREG_OFFSET_CAPTURE, $offset)) { $str .= "hello"; unset($parse); } }' ], ]; } /** * @return iterable */ public function providerInvalidCodeParse() { return [ 'whileTrueNoBreak' => [ ' 'UndefinedGlobalVariable', ], 'invalidateByRefAssignmentWithRedundantCondition' => [ ' 'RedundantCondition', ], ]; } }