,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'validSimpleAnnotations' => [ 'getString(); $b = $child::getInt();', 'assertions' => [ '$a' => 'string', '$b' => 'int', ], ], 'anotherSimpleExample' => [ 'b = new B(); } public function c(string $s) : void {} /** * @param array $arguments * @return mixed */ public function __call(string $method, array $arguments) { return $this->b->$method(...$arguments); } } class B { public function b(): void { echo "b"; } public function c(int $s) : void {} } $a = new A(); $a->b();' ], 'allowConstructor' => [ 'i = 1; } } class M { public function __construct() {} } /** * @mixin M */ class A extends AParent {}' ], 'implicitMixin' => [ 'valid()) { if (!$iterator->isDot() && $iterator->isLink()) {} $iterator->next(); } }' ], 'wrapCustomIterator' => [ 'index(0);', [ '$b' => 'bool', ] ], 'templatedMixin' => [ ' */ class Bar {} $bar = new Bar(); $b = $bar->hi();', [ '$b' => 'string', ] ], 'templatedMixinSelf' => [ 'item = $item; } /** * @return T */ public function get() { return $this->item; } } /** * @mixin Animal */ class Dog { public function __construct() {} } function getDog(): Dog { return (new Dog())->get(); }' ], 'inheritPropertyAnnotations' => [ 'foo; }' ], 'inheritTemplatedMixinWithStatic' => [ 'var = $var; } /** * @psalm-return T */ public function type() { return $this->var; } } /** * @template T as object * @mixin Mixin * @psalm-consistent-constructor */ abstract class Foo { /** @var Mixin */ public object $obj; public function __call(string $name, array $args) { return $this->obj->$name(...$args); } public function __callStatic(string $name, array $args) { return (new static)->obj->$name(...$args); } } /** * @extends Foo */ abstract class FooChild extends Foo{} /** * @psalm-suppress MissingConstructor */ final class FooGrandChild extends FooChild {} function test2() : FooGrandChild { return FooGrandChild::type(); } function test() : FooGrandChild { return (new FooGrandChild)->type(); }' ], 'inheritTemplatedMixinWithStaticAndFinalClass' => [ 'var = $var; } /** * @psalm-return self */ public function getMixin() { return $this; } } /** * @template T as object * @mixin Mixin */ abstract class Foo { /** @var Mixin */ public object $obj; public function __call(string $name, array $args) { return $this->obj->$name(...$args); } } /** * @extends Foo */ abstract class FooChild extends Foo{} /** * @psalm-suppress MissingConstructor */ final class FooGrandChild extends FooChild {} /** * @psalm-return Mixin */ function test() : Mixin { return (new FooGrandChild)->getMixin(); }' ], 'mixinParseWithTextAfter' => [ ' [ 't = $t; } public function __call(string $method, array $parameters) { /** @psalm-suppress MixedMethodCall */ return $this->t->$method($parameters); } } /** * @method self active() */ class Model { /** * @return Builder */ public function query(): Builder { return new Builder($this); } public function __call(string $method, array $parameters) { if ($method === "active") { return new Model(); } } } /** @param Builder $b */ function foo(Builder $b) : Model { return $b->active(); }' ], 'multipleMixins' => [ 'a(); $b = $test->b();', 'assertions' => [ '$a' => 'string', '$b' => 'int', ], ], 'inheritMultipleTemplatedMixinsWithStatic' => [ 'var = $var; } /** * @psalm-return T */ public function type() { return $this->var; } } /** * @template T */ class OtherMixin { /** * @psalm-var T */ private $var; /** * @psalm-param T $var */ public function __construct ($var) { $this->var = $var; } /** * @psalm-return T */ public function other() { return $this->var; } } /** * @template T as object * @template T2 as string * @mixin Mixin * @mixin OtherMixin * @psalm-consistent-constructor */ abstract class Foo { /** @var Mixin */ public object $obj; /** @var OtherMixin */ public object $otherObj; public function __call(string $name, array $args) { if ($name === "test") { return $this->obj->$name(...$args); } return $this->otherObj->$name(...$args); } public function __callStatic(string $name, array $args) { if ($name === "test") { return (new static)->obj->$name(...$args); } return (new static)->otherObj->$name(...$args); } } /** * @extends Foo */ abstract class FooChild extends Foo{} /** * @psalm-suppress MissingConstructor */ final class FooGrandChild extends FooChild {} function test() : FooGrandChild { return FooGrandChild::type(); } function testStatic() : FooGrandChild { return (new FooGrandChild)->type(); } function other() : string { return FooGrandChild::other(); } function otherStatic() : string { return (new FooGrandChild)->other(); }' ], 'multipleMixinsWithSameMethod' => [ 'foo();' ], 'templatedMixinBindStatic' => [ ' */ public function getInner() { return []; } } /** * @mixin QueryBuilder */ abstract class Model {} class FooModel extends Model {} $f = new FooModel(); $g = $f->getInner();', [ '$g' => 'list', ] ], ]; } /** * @return iterable */ public function providerInvalidCodeParse(): iterable { return [ 'undefinedMixinClass' => [ ' 'UndefinedDocblockClass' ], 'undefinedMixinClassWithPropertyFetch' => [ 'foo;', 'error_message' => 'UndefinedPropertyFetch' ], 'undefinedMixinClassWithPropertyAssignment' => [ 'foo = "bar";', 'error_message' => 'UndefinedPropertyAssignment' ], 'undefinedMixinClassWithMethodCall' => [ 'foo();', 'error_message' => 'UndefinedMethod' ], 'inheritTemplatedMixinWithSelf' => [ 'var = $var; } /** * @psalm-return T */ public function type() { return $this->var; } } /** * @template T as object * @mixin Mixin */ abstract class Foo { /** @var Mixin */ public object $obj; public function __call(string $name, array $args) { return $this->obj->$name(...$args); } } /** * @extends Foo */ abstract class FooChild extends Foo{} /** * @psalm-suppress MissingConstructor */ final class FooGrandChild extends FooChild {} function test() : FooGrandChild { return (new FooGrandChild)->type(); }', 'error_message' => 'LessSpecificReturnStatement' ], ]; } }