[ 'code' => ' [ '$a' => 'null|string', ], ], 'nullableReturnTypeInDocblock' => [ 'code' => ' [ '$a' => 'null|string', ], ], 'nullableArgument' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ '$id1' => 'int', '$name1' => 'string', '$id2' => 'int', '$name2' => 'string', ], ], 'arrayDestructuringInForeach' => [ 'code' => ' [ 'code' => ' 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' => [ 'code' => ' 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' => [ 'code' => ' 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' => [ 'code' => ' $iter */ function iterator(iterable $iter): void { foreach ($iter as $val) { // } } iterator([1, 2, 3, 4]); /** @psalm-suppress MixedArgumentTypeCoercion */ iterator(new SplFixedArray(5));', ], 'traversableObject' => [ 'code' => ' */ class IteratorObj implements Iterator { function rewind(): void {} /** @return mixed */ function current() { return null; } function key(): int { return 0; } function next(): void {} function valid(): bool { return false; } } function foo(\Traversable $t): void { } foo(new IteratorObj);', ], 'iterableIsArrayOrTraversable' => [ 'code' => ' [ 'code' => ' [ 'code' => ' $traversable * @return array */ function toArray(Traversable $traversable): array { return iterator_to_array($traversable); }', ], 'noReservedWordInDocblock' => [ 'code' => ' [ 'code' => ' "first", "dos" => "second"]); [0 => $first, "dos" => $second] = $var; echo $first; echo $second;', ], ]; } /** * */ public function providerInvalidCodeParse(): iterable { return [ 'invalidPrivateClassConstFetch' => [ 'code' => ' 'InaccessibleClassConstant', ], 'invalidPrivateClassConstFetchFromSubclass' => [ 'code' => ' 'InaccessibleClassConstant', ], 'invalidProtectedClassConstFetch' => [ 'code' => ' 'InaccessibleClassConstant', ], 'invalidIterableArg' => [ 'code' => ' $iter */ function iterator(iterable $iter): void { foreach ($iter as $val) { // } } class A { } iterator(new A());', 'error_message' => 'InvalidArgument', ], 'voidDoesntWorkIn70' => [ 'code' => ' 'ReservedWord', 'ignored_issues' => [], 'php_version' => '7.0', ], 'objectDoesntWorkIn71' => [ 'code' => ' 'ReservedWord', 'ignored_issues' => [], 'php_version' => '7.0', ], 'arrayDestructuringInvalidList' => [ 'code' => ' 'InvalidArrayOffset', ], 'arrayDestructuringInvalidArray' => [ 'code' => ' 'InvalidArrayOffset', ], ]; } }