,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'simplePureFunction' => [ 'a === 2) { return $i; } $a = new A(); return null; }', ], 'pureFunctionCallingBuiltinFunctions' => [ ' [ '$1", $output); return $output; }' ], 'implicitAnnotations' => [ 'setOptions($options); $this->setDefaultOptions($this->getOptions()); } function getOptions(): array { return $this->options; } function setOptions(array $options): void { $this->options = $options; } function setDefaultOptions(array $defaultOptions): void { $this->defaultOptions = $defaultOptions; } }', ], 'canCreateObjectWithNoExternalMutations' => [ 'count = $count; } public function increment() : void { $this->count++; } public function incrementByTwo() : void { $this->count = $this->count + 2; } public function incrementByFive() : void { $this->count += 5; } } /** @psalm-pure */ function makesACounter(int $i) : Counter { $c = new Counter($i); $c->increment(); $c->incrementByTwo(); $c->incrementByFive(); return $c; }', ], 'canCreateImmutableObject' => [ 's = $s; } public function getShort() : string { return substr($this->s, 0, 5); } } /** @psalm-pure */ function makeA(string $s) : A { $a = new A($s); if ($a->getShort() === "bar") { return new A("foo"); } return $a; }' ], 'assertIsPureInProductionn' => [ ' [ ' [ ' [ ' $b; }); return $ar[0] ?? 0; }', ], 'allowPureToString' => [ ' */ public function providerInvalidCodeParse() { return [ 'impurePropertyAssignment' => [ 'a++; if ($i % 2 === 0 || $a->a === 2) { return $i; } return null; }', 'error_message' => 'ImpurePropertyAssignment', ], 'impureMethodCall' => [ 'a++; } } /** @psalm-pure */ function filterOdd(int $i, A $a) : ?int { $a->foo(); if ($i % 2 === 0 || $a->a === 2) { return $i; } return null; }', 'error_message' => 'ImpureMethodCall', ], 'impureFunctionCall' => [ ' 'ImpureFunctionCall', ], 'impureConstructorCall' => [ 'a++; } } /** @psalm-pure */ function filterOdd(int $i, A $a) : ?int { $b = new B($a); if ($i % 2 === 0 || $a->a === 2) { return $i; } return null; }', 'error_message' => 'ImpureMethodCall', ], 'canCreateObjectWithNoExternalMutations' => [ 'count = $count; } public function increment() : void { $this->count += rand(0, 5); } } /** @psalm-pure */ function makesACounter(int $i) : Counter { $c = new Counter($i); $c->increment(); return $c; }', 'error_message' => 'ImpureMethodCall', ], 'useOfStaticMakesFunctionImpure' => [ ' 'ImpureStaticVariable', ], 'preventImpureArrayMapClosure' => [ ' 'ImpureFunctionCall', ], 'sortFunctionImpure' => [ ' $b; }); return $ar[0] ?? 0; }', 'error_message' => 'ImpureFunctionCall', ], 'impureByRef' => [ ' 'ImpureByReferenceAssignment' ], 'staticPropertyFetch' => [ ' 'ImpureStaticProperty', ], 'staticPropertyAssignment' => [ ' 'ImpureStaticProperty', ], 'preventImpureToStringViaComparison' => [ ' 'ImpureMethodCall' ], 'preventImpureToStringViaConcatenation' => [ ' 'ImpureMethodCall' ], ]; } }