,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'nullableReturnType' => [ ' [ '$a' => 'null|string', ], ], 'nullableReturnTypeInDocblock' => [ ' [ '$a' => 'null|string', ], ], 'nullableArgument' => [ ' [ ' [ ' [ ' [ ' [ '$id1' => 'int', '$name1' => 'string', '$id2' => 'int', '$name2' => 'string', ], ], 'arrayDestructuringInForeach' => [ ' [ ' 1, "name" => "Tom"], ["id" => 2, "name" => "Fred"], ]; // list() style list("id" => $id1, "name" => $name1) = $data[0]; // [] style ["id" => $id2, "name" => $name2] = $data[1];', 'assertions' => [ '$id1' => 'int', '$name1' => 'string', '$id2' => 'int', '$name2' => 'string', ], ], 'arrayListDestructuringInForeachWithKeys' => [ ' 1, "name" => "Tom"], ["id" => 2, "name" => "Fred"], ]; // list() style foreach ($data as list("id" => $id, "name" => $name)) { $last_id = $id; $last_name = $name; }', 'assertions' => [ '$last_id' => 'int', '$last_name' => 'string', ], ], 'arrayDestructuringInForeachWithKeys' => [ ' 1, "name" => "Tom"], ["id" => 2, "name" => "Fred"], ]; // [] style foreach ($data as ["id" => $id, "name" => $name]) { $last_id = $id; $last_name = $name; }', 'assertions' => [ '$last_id' => 'int', '$last_name' => 'string', ], ], 'iterableArg' => [ ' $iter */ function iterator(iterable $iter): void { foreach ($iter as $val) { // } } iterator([1, 2, 3, 4]); /** @psalm-suppress MixedArgumentTypeCoercion */ iterator(new SplFixedArray(5));', ], 'traversableObject' => [ ' [ ' [ ' [ ' [ ' "first", "dos" => "second"]); [0 => $first, "dos" => $second] = $var; echo $first; echo $second;', ], ]; } /** * @return iterable */ public function providerInvalidCodeParse(): iterable { return [ 'invalidPrivateClassConstFetch' => [ ' 'InaccessibleClassConstant', ], 'invalidPrivateClassConstFetchFromSubclass' => [ ' 'InaccessibleClassConstant', ], 'invalidProtectedClassConstFetch' => [ ' 'InaccessibleClassConstant', ], 'invalidIterableArg' => [ ' $iter */ function iterator(iterable $iter): void { foreach ($iter as $val) { // } } class A { } iterator(new A());', 'error_message' => 'InvalidArgument', ], 'voidDoesntWorkIn70' => [ ' 'ReservedWord', [], false, '7.0', ], 'objectDoesntWorkIn71' => [ ' 'ReservedWord', [], false, '7.0', ], 'arrayDestructuringInvalidList' => [ ' 'InvalidArrayOffset', ], 'arrayDestructuringInvalidArray' => [ ' 'InvalidArrayOffset', ], ]; } }