,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'immutableClassGenerating' => [ 'a = $a; $this->b = $b; } public function setA(int $a) : self { return new self($a, $this->b); } }', ], 'callInternalClassMethod' => [ 'a = $a; } public function getA() : string { return $this->a; } public function getHelloA() : string { return "hello" . $this->getA(); } }', ], 'addToCart' => [ 'items = $items; } public function addItem(CartItem $item) : self { $items = $this->items; $items[] = $item; return new Cart($items); } } /** @psalm-immutable */ class CartItem { public string $name; public float $price; public function __construct(string $name, float $price) { $this->name = $name; $this->price = $price; } } /** @psalm-pure */ function addItemToCart(Cart $c, string $name, float $price) : Cart { return $c->addItem(new CartItem($name, $price)); }', ], 'allowImpureStaticMethod' => [ 'id = $id; } public static function fromString(string $id): self { return new self($id . rand(0, 1)); } }' ] ]; } /** * @return iterable */ public function providerInvalidCodeParse() { return [ 'immutablePropertyAssignmentInternally' => [ 'a = $a; $this->b = $b; } public function setA(int $a): void { $this->a = $a; } }', 'error_message' => 'ImpurePropertyAssignment', ], 'immutablePropertyAssignmentExternally' => [ 'a = $a; $this->b = $b; } } $a = new A(4, "hello"); $a->b = "goodbye";', 'error_message' => 'InaccessibleProperty', ], 'callImpureFunction' => [ 'a = $a; $this->b = $b; } public function bar() : void { header("Location: https://vimeo.com"); } }', 'error_message' => 'ImpureFunctionCall', ], 'callExternalClassMethod' => [ 'a = $a; } public function getA() : string { return $this->a; } public function redirectToA() : void { B::setRedirectHeader($this->getA()); } } class B { public static function setRedirectHeader(string $s) : void { header("Location: $s"); } }', 'error_message' => 'ImpureMethodCall', ], ]; } }