,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'worksAfterConvert' => [ 'convert(); $f->test(); ' ], 'withTemplate' => [ 'state = $state; } /** * @param string $name * @param mixed $val * @psalm-if-this-is Foo * @return void */ public function set($name, $val) { } /** * @return Foo */ public function freeze() { /** @var Foo */ $f = clone $this; return $f; } } $f = new Foo(new Unfrozen()); $f->set("asd", 10); ' ], 'subclass' => [ 'test(); ' ], 'ifThisIsWithSelfAlias' => [ ' * @psalm-this-out self<"started"> */ public function start(): void { throw new RuntimeException("???"); } } /** @var App<"idle"> */ $app = new App(); $app->start(); ' ], 'ifThisIsAndThisOutAtTheSameTime' => [ ' * @psalm-this-out App<"started"> */ public function start(): void { throw new RuntimeException("???"); } } /** @var App<"idle"> */ $app = new App(); $app->start(); ' ], 'ifThisIsChangeThisTypeInsideMethod' => [ ' */ private $items; /** * @param list $items */ public function __construct(array $items) { $this->items = $items; } /** * @psalm-if-this-is ArrayList> * @return ArrayList */ public function compact(): ArrayList { $values = []; foreach ($this->items as $item) { $value = $item->unwrap(); if (null !== $value) { $values[] = $value; } } return new self($values); } } /** @var ArrayList> $list */ $list = new ArrayList([]); $numbers = $list->compact(); ', 'assertions' => [ '$numbers' => 'ArrayList' ], ], 'ifThisIsResolveTemplateParams' => [ ' */ private $items; /** * @param list $items */ public function __construct(array $items) { $this->items = $items; } /** * @template A * @template B * @template TOption of Option * @template TEither of Either * * @psalm-if-this-is ArrayList * @return ArrayList */ public function compact(): ArrayList { $values = []; foreach ($this->items as $item) { $value = $item->unwrap(); if (null !== $value) { $values[] = $value; } } return new self($values); } } /** @var ArrayList|Option> $list */ $list = new ArrayList([]); $numbers = $list->compact(); ', 'assertions' => [ '$numbers' => 'ArrayList' ], ], ]; } /** * @return array */ public function providerInvalidCodeParse(): iterable { return [ 'failsWithWrongTemplate1' => [ 'data = $data; } /** * @psalm-if-this-is a */ public function test(): void { } } $i = new a("test"); $i->test(); ', 'error_message' => 'IfThisIsMismatch' ], 'failsWithWrongTemplate2' => [ 'state = $state; } /** * @param string $name * @param mixed $val * @psalm-if-this-is Foo * @return void */ public function set($name, $val) {} /** * @return Foo */ public function freeze() { /** @var Foo */ $f = clone $this; return $f; } } $f = new Foo(new Unfrozen()); $f->set("asd", 10); $g = $f->freeze(); $g->set("asd", 20); // Fails ', 'error_message' => 'IfThisIsMismatch' ], 'failWithInvalidTemplateConstraint' => [ '> * @return ArrayList */ public function compact(): ArrayList { throw new RuntimeException("???"); } } /** @var ArrayList $list */ $list = new ArrayList(); $numbers = $list->compact();', 'error_message' => 'IfThisIsMismatch' ], ]; } }