,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'typeAliasBeforeClass' => [ ' [ ' [ ' [ ' [ ' */ class Bar { public function foo() : void { $bar = /** @return TA */ function() { return ["hello"]; }; /** @var array */ $bat = [$bar(), $bar()]; foreach ($bat as $b) { echo $b[0]; } } } /** * @psalm-type _A=array{elt:int} * @param _A $p * @return _A */ function f($p) { /** @var _A */ $r = $p; return $r; }', ], 'classTypeAlias' => [ ' "Nokia"]; } } /** @psalm-type NameType = array{name: string} */ class Name { /** @psalm-return NameType */ function toArray(): array { return ["name" => "Matt"]; } } /** * @psalm-import-type PhoneType from Phone as PhoneType2 * @psalm-import-type NameType from Name as NameType2 * * @psalm-type UserType = PhoneType2&NameType2 */ class User { /** @psalm-return UserType */ function toArray(): array { return array_merge( (new Name)->toArray(), (new Phone)->toArray() ); } }' ], 'classTypeAliasImportWithAlias' => [ ' "Nokia"]; } } /** * @psalm-import-type PhoneType from Phone as TPhone */ class User { /** @psalm-return TPhone */ function toArray(): array { return array_merge([], (new Phone)->toArray()); } }' ], 'classTypeAliasDirectUsage' => [ ' "Nokia"]; } } /** * @psalm-import-type PhoneType from Phone */ class User { /** @psalm-return PhoneType */ function toArray(): array { return array_merge([], (new Phone)->toArray()); } }' ], 'classTypeAliasFromExternalNamespace' => [ ' "Nokia"]; } } } namespace Bar { /** * @psalm-import-type PhoneType from \Foo\Phone */ class User { /** @psalm-return PhoneType */ function toArray(): array { return (new \Foo\Phone)->toArray(); } } }' ], 'importTypeForParam' => [ 'b($type); } /** * @psalm-param Type2 $type */ private function b(int $type): void { } }' ], ]; } /** * @return iterable */ public function providerInvalidCodeParse() { return [ 'invalidTypeAlias' => [ ' */ class A {}', 'error_message' => 'InvalidDocblock', ], 'typeAliasInObjectLike' => [ ' 'InvalidReturnStatement', ], 'classTypeAliasInvalidReturn' => [ ' "Nokia"]; } } /** @psalm-type NameType = array{name: string} */ class Name { /** @psalm-return NameType */ function toArray(): array { return ["name" => "Matt"]; } } /** * @psalm-import-type PhoneType from Phone as PhoneType2 * @psalm-import-type NameType from Name as NameType2 * * @psalm-type UserType = PhoneType2&NameType2 */ class User { /** @psalm-return UserType */ function toArray(): array { return array_merge( (new Name)->toArray(), ["foo" => "bar"] ); } }', 'error_message' => 'InvalidReturnStatement', ], 'classTypeInvalidAlias' => [ ' "Matt"]; } } /** * @psalm-import-type PhoneType from Phone */ class User { /** @psalm-return UserType */ function toArray(): array { return (new Phone)->toArray(); } }', 'error_message' => 'UndefinedDocblockClass', ], 'classTypeAliasFromInvalidClass' => [ ' 'UndefinedDocblockClass', ], ]; } }