,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'byRefUseVar' => [ ' [ ' [ ' $a . "blah", $bar );', ], 'varReturnType' => [ ' [ '$a' => 'int', ], ], 'varReturnTypeArray' => [ ' $a + 1; $a = $add_one(1);', 'assertions' => [ '$a' => 'int', ], ], 'varCallableParamReturnType' => [ ' [ ' [ ' $a . "blah"; }', ], 'callable' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ '$a' => 'array{0: string, 1: string}', '$b' => 'array{0: string, 1: string}', '$c' => 'array{0: string, 1: string}', '$d' => 'array{0: string, 1: string}', '$e' => 'array{0: string, 1: string}', '$f' => 'array{0: string, 1: string}', ], ], 'arrayCallableMethod' => [ ' [ ' [ ' $b ? 1 : 0; } $arr = [5, 4, 3, 1, 2]; usort($arr, "fooBar"); } }', ], 'closureSelf' => [ 'subitems = array_map( function(self $i): self { return $i; }, $in ); } } new A([new A, new A]);', ], 'possiblyUndefinedFunction' => [ ' [ ' [ ' [ 'callMeMaybe("foo");', ], 'isCallableString' => [ ' [ ' [ 'callable = $callable; } public function callTheCallableDirectly(): bool { return ($this->callable)(); } public function callTheCallableIndirectly(): bool { $r = $this->callable; return $r(); } }', ], 'invokableProperties' => [ 'invokable = $invokable; } public function callTheInvokableDirectly(): bool { return ($this->invokable)(); } public function callTheInvokableIndirectly(): bool { $r = $this->invokable; return $r(); } }', ], 'nullableReturnTypeShorthand' => [ ' [ ' [ ' [ ' [ ' $b; } } f("strcmp"); f([new C, "m"]); f([C::class, "m"]);', ], 'callableWithSpaces' => [ ' [ ' [ 'func2(function(B $x): void {}); $c->func2(function(B $x): void {}); class A {} class B extends A { /** * @param callable(self) $f */ function func2(callable $f): void { $f($this); } }', ], 'callableParentArg' => [ 'func3(function(A $x): void {}); $c->func3(function(A $x): void {}); class A {} class B extends A { /** * @param callable(parent) $f */ function func3(callable $f): void { $f($this); } }', ], 'callableStaticArg' => [ 'func1(function(B $x): void {}); $c->func1(function(C $x): void {}); class A {} class B extends A { /** * @param callable(static) $f */ function func1(callable $f): void { $f($this); } }', ], 'callableStaticReturn' => [ 'func1(function(): C { return new C(); });', ], 'callableSelfReturn' => [ 'func2(function() { return new B(); }); $c->func2(function() { return new C(); });', ], 'callableParentReturn' => [ 'func3(function() { return new A(); });', ], 'selfArrayMapCallableWrongClass' => [ ' */ public function bar() { return array_map([Foo::class, "foo"], [1,2,3]); } /** @return array */ public function bat() { return array_map([Foo::class, "baz"], [1]); } }', ], 'dynamicCallableArray' => [ 'value = $value; } }', ], 'callableIsArrayAssertion' => [ ' [ ' [ ' [ ' [ ' [ ' [ 'id = $id; } /** * @return static */ final public static function fromString(string $id): self { return new static($id); } } final class CriterionId extends Id { } final class CriterionIds { /** * @psalm-var non-empty-list */ private $ids; /** * @psalm-param non-empty-list $ids */ private function __construct(array $ids) { $this->ids = $ids; } /** * @psalm-param non-empty-list $ids */ public static function fromStrings(array $ids): self { return new self(array_map([CriterionId::class, "fromString"], $ids)); } }' ], 'offsetOnCallable' => [ ' [ ' 'class-string|object', '$method' => 'string' ] ], 'callableInterface' => [ ' [ ' "ASC", "start_time" => "ASC"]);' ], 'callOnInvokableOrCallable' => [ ' */ public function providerInvalidCodeParse() { return [ 'undefinedCallableClass' => [ 'getFoo()($argOne, $argTwo); } }', 'error_message' => 'InvalidFunctionCall', 'error_levels' => ['UndefinedClass', 'MixedInferredReturnType'], ], 'undefinedCallableMethodFullString' => [ ' 'UndefinedMethod', ], 'undefinedCallableMethodClassConcat' => [ ' 'UndefinedMethod', ], 'undefinedCallableMethodArray' => [ ' 'InvalidArgument', ], 'undefinedCallableMethodArrayWithoutClass' => [ ' 'InvalidArgument', ], 'undefinedCallableMethodClass' => [ ' 'UndefinedClass', ], 'undefinedCallableFunction' => [ ' 'UndefinedFunction', ], 'stringFunctionCall' => [ ' 'MixedAssignment', ], 'wrongCallableReturnType' => [ ' 'InvalidReturnStatement', ], 'checkCallableTypeString' => [ ' 'InvalidScalarArgument', ], 'checkCallableTypeArrayInstanceFirstArg' => [ ' $b; } } f([new C, "m"]);', 'error_message' => 'InvalidScalarArgument', ], 'checkCallableTypeArrayClassStringFirstArg' => [ ' $b; } } f([C::class, "m"]);', 'error_message' => 'InvalidScalarArgument', ], 'callableWithSpaceAfterColonBadVarArg' => [ 'p = function (string $s, string $t): stdClass { return new stdClass; }; } }', 'error_message' => 'InvalidPropertyAssignmentValue', ], 'callableWithSpaceBeforeColonBadVarArg' => [ 'p = function (string $s, string $t): stdClass { return new stdClass; }; } }', 'error_message' => 'InvalidPropertyAssignmentValue', ], 'callableWithSpacesEitherSideOfColonBadVarArg' => [ 'p = function (string $s, string $t): stdClass { return new stdClass; }; } }', 'error_message' => 'InvalidPropertyAssignmentValue', ], 'badArrayMapArrayCallable' => [ ' 'InvalidArgument', ], 'noFatalErrorOnMissingClassWithSlash' => [ ' 'InvalidArgument' ], 'noFatalErrorOnMissingClassWithoutSlash' => [ ' 'InvalidArgument' ], 'preventStringDocblockType' => [ ' 'MismatchingDocblockParamType', ], 'moreSpecificCallable' => [ ' 'MixedArgumentTypeCoercion' ], 'undefinedVarInBareCallable' => [ ' 'UndefinedVariable', ], 'dontQualifyStringCallables' => [ ' 'UndefinedFunction', ], ]; } }