,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; } public final function setOptions(array $options): void { $this->options = $options; } public final 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' => [ ' [ 'getMessage(); } echo getMessage(new Exception("test"));' ], 'exceptionGetCode' => [ 'getCode(); } echo getCode(new Exception("test"));' ], 'exceptionGetFile' => [ 'getFile(); } echo getFile(new Exception("test"));' ], 'exceptionGetLine' => [ 'getLine(); } echo getLine(new Exception("test"));' ], 'exceptionGetTrace' => [ 'getTrace(); } echo count(getTrace(new Exception("test")));' ], 'exceptionGetPrevious' => [ 'getPrevious(); } echo gettype(getPrevious(new Exception("test")));' ], 'exceptionGetTraceAsString' => [ 'getTraceAsString(); } echo getTraceAsString(new Exception("test"));' ], 'callingMethodInThrowStillPure' => [ ' 9000) { throw MyException::hello(); } if ($sum > 90001) { throw new MyException(); } return $sum; }' ], 'countMethodCanBePure' => [ ' */ 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' ], 'countCanBeImpure' => [ ' 'ImpureFunctionCall', ], ]; } }