,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'byRefUseVar' => [ ' [ ' [ ' [ '$a' => 'int', ], ], 'varCallableParamReturnType' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ '$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}', ], ], 'arrayMapClosureVar' => [ ' [ '$a' => 'array{0: int, 1: int, 2: int}', ], ], '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' => [ ' [ ' [ ' [ ' [ '$a' => 'A', ], ], 'returnsTypedClosureWithSubclassParam' => [ ' [ '$a' => 'A', ], ], 'returnsTypedClosureWithParentReturn' => [ ' [ '$a' => 'A', ], ], 'returnsTypedCallableFromClosure' => [ ' [ '$a' => 'A', ], ], 'inferClosureTypeWithTypehint' => [ ' [ '$adder1' => 'Closure(int):Closure(int):int', '$adder2' => 'Closure(int):Closure(int):int', ], 'error_levels' => ['MissingClosureReturnType'], ], 'inferArrayMapReturnTypeWithoutTypehints' => [ ' [], 'error_levels' => ['MissingClosureReturnType'], ], 'inferArrayMapReturnTypeWithTypehints' => [ ' [ ' [ '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(); } }', ], 'PHP71-mirrorCallableParams' => [ ' 0; }));', ], 'singleLineClosures' => [ ' [ '$a' => 'Closure():Closure():string(hello)', '$b' => 'string', ], ], 'nullableReturnTypeShorthand' => [ ' [ ' [ ' [ ' [ ' [ ' $b; } } f("strcmp"); f([new C, "m"]); f([C::class, "m"]);', ], 'callableWithSpaces' => [ ' [ ' [ ' 0; } } acceptsIntToBool(Closure::fromCallable(new NamedInvokable));', ], 'PHP71-closureFromCallableInvokableAnonymousClass' => [ ' 0; } }; acceptsIntToBool(Closure::fromCallable($anonInvokable));', ], 'callableSelfArg' => [ '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); } }', ], 'callableSelfReturn' => [ 'func1(function(): B { return new B(); }); $c->func1(function(): C { return new C(); }); $b->func2(function(): B { return new B(); }); $c->func2(function(): B { return new B(); });', ], '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; } }', ], 'PHP71-publicCallableFromInside' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' */ public function providerInvalidCodeParse() { return [ 'wrongArg' => [ ' 'InvalidScalarArgument', ], 'noReturn' => [ ' 'InvalidReturnType', ], 'undefinedCallableClass' => [ 'getFoo()($argOne, $argTwo); } }', 'error_message' => 'InvalidFunctionCall', 'error_levels' => ['UndefinedClass', 'MixedInferredReturnType'], ], 'undefinedCallableMethodFullString' => [ ' 'UndefinedMethod', ], 'undefinedCallableMethodClassConcat' => [ ' 'UndefinedMethod', ], 'undefinedCallableMethodArray' => [ ' 'InvalidArgument', ], 'undefinedCallableMethodArrayWithoutClass' => [ ' 'InvalidArgument', ], 'undefinedCallableMethodClass' => [ ' 'UndefinedClass', ], 'undefinedCallableFunction' => [ ' 'UndefinedFunction', ], 'possiblyNullFunctionCall' => [ ' 'MixedReturnStatement', ], 'stringFunctionCall' => [ ' 'MixedAssignment', ], 'wrongParamType' => [ ' 'InvalidScalarArgument', ], 'missingClosureReturnType' => [ ' 'MissingClosureReturnType', ], 'wrongCallableReturnType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedClosureWithBadReturnType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedCallableWithBadReturnType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedClosureWithBadParamType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedCallableWithBadParamType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedClosureWithBadCall' => [ ' 'InvalidArgument', ], 'returnsTypedClosureWithSubclassParam' => [ ' 'LessSpecificReturnStatement', ], 'returnsTypedClosureWithSubclassReturn' => [ ' 'LessSpecificReturnStatement', ], 'returnsTypedClosureFromCallable' => [ ' 'LessSpecificReturnStatement', ], 'undefinedVariable' => [ ' 'UndefinedVariable', ], 'voidReturningArrayMap' => [ ' 'TypeDoesNotContainType', ], 'checkCallableTypeString' => [ ' 'InvalidScalarArgument', ], 'checkCallableTypeArrayInstanceFirstArg' => [ ' $b; } } f([new C, "m"]);', 'error_message' => 'InvalidScalarArgument', ], 'checkCallableTypeArrayClassStringFirstArg' => [ ' $b; } } f([C::class, "m"]);', 'error_message' => 'InvalidScalarArgument', ], 'PHP71-closureFromCallableInvokableNamedClassWrongArgs' => [ ' 0; } } acceptsIntToBool(Closure::fromCallable(new NamedInvokable));', 'error_message' => 'InvalidScalarArgument', ], 'undefinedClassForCallable' => [ ' 'UndefinedClass', ], 'useDuplicateName' => [ ' 'DuplicateParam', ], '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', ], 'PHP71-privateCallable' => [ ' 'InvalidArgument', ], 'prohibitCallableWithRequiredArg' => [ ' 'InvalidArgument', ], 'useClosureDocblockType' => [ ' 'ArgumentTypeCoercion - src/somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided', ], 'closureByRefUseToMixed' => [ ' 'MixedReturnStatement' ], ]; } }