,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'byRefUseVar' => [ ' [ ' [ ' $a . "blah", $bar );', 'assertions' => [], 'error_levels' => [], '7.4' ], 'varReturnType' => [ ' [ '$a' => 'int', ], ], 'varReturnTypeArray' => [ ' $a + 1; $a = $add_one(1);', 'assertions' => [ '$a' => 'int', ], 'error_levels' => [], '7.4' ], 'correctParamType' => [ ' [ ' [ '$a' => 'array{int, int, int}', ], ], 'inlineCallableFunction' => [ ' $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]);', ], 'arrayMapVariadicClosureArg' => [ ' [ ' [ ' $f($g($x)); }', 'assertions' => [], 'error_levels' => [], '7.4' ], 'returnsTypedClosureWithClasses' => [ ' [ '$a' => 'A', ], ], 'returnsTypedClosureWithSubclassParam' => [ ' [ '$a' => 'A', ], ], 'returnsTypedClosureWithParentReturn' => [ ' [ '$a' => 'A', ], ], 'inferArrayMapReturnTypeWithoutTypehints' => [ ' [], 'error_levels' => ['MissingClosureReturnType'], ], 'inferArrayMapReturnTypeWithTypehints' => [ ' [ 'invokable = $invokable; } public function callTheInvokableDirectly(): bool { return ($this->invokable)(); } public function callTheInvokableIndirectly(): bool { $r = $this->invokable; return $r(); } }', ], 'PHP71-mirrorCallableParams' => [ ' 0; }));', ], 'singleLineClosures' => [ ' [ '$a' => 'pure-Closure():pure-Closure():string(hello)', '$b' => 'string', ], ], 'voidReturningArrayMap' => [ ' [ ' 0; } } acceptsIntToBool(Closure::fromCallable(new NamedInvokable));', ], 'PHP71-closureFromCallableInvokableAnonymousClass' => [ ' 0; } }; acceptsIntToBool(Closure::fromCallable($anonInvokable));', ], 'PHP71-publicCallableFromInside' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'a = fn(int $a) : int => $a + 5; } public function invoker(int $b) : int { return $this->a->__invoke($b); } }', 'assertions' => [], 'error_levels' => [], '7.4' ], 'annotateShortClosureReturn' => [ ' /** @var bool */ returnsBool();', [], [], '7.4' ], 'rememberParentAssertions' => [ 'a instanceof A) { function () use ($a): void { $a->a->foo(); }; } }' ], ]; } /** * @return iterable */ public function providerInvalidCodeParse(): iterable { return [ 'wrongArg' => [ ' 'InvalidScalarArgument', ], 'noReturn' => [ ' 'InvalidReturnType', ], 'possiblyNullFunctionCall' => [ ' 'MixedReturnStatement', ], 'wrongParamType' => [ ' 'InvalidScalarArgument', ], 'missingClosureReturnType' => [ ' 'MissingClosureReturnType', ], 'returnsTypedClosureWithBadReturnType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedCallableWithBadReturnType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedClosureWithBadParamType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedCallableWithBadParamType' => [ ' 'InvalidReturnStatement', ], 'returnsTypedClosureWithBadCall' => [ ' 'InvalidArgument', ], 'returnsTypedClosureWithSubclassParam' => [ ' 'LessSpecificReturnStatement', ], 'returnsTypedClosureWithSubclassReturn' => [ ' 'LessSpecificReturnStatement', ], 'returnsTypedClosureFromCallable' => [ ' 'LessSpecificReturnStatement', ], 'undefinedVariable' => [ ' 'UndefinedVariable', ], 'voidReturningArrayMap' => [ ' 'TypeDoesNotContainType', ], 'PHP71-closureFromCallableInvokableNamedClassWrongArgs' => [ ' 0; } } acceptsIntToBool(Closure::fromCallable(new NamedInvokable));', 'error_message' => 'InvalidScalarArgument', ], 'undefinedClassForCallable' => [ ' 'UndefinedClass', ], 'useDuplicateName' => [ ' 'DuplicateParam', ], 'PHP71-privateCallable' => [ ' 'InvalidArgument', ], 'prohibitCallableWithRequiredArg' => [ ' 'InvalidArgument', ], 'useClosureDocblockType' => [ ' 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided', ], 'closureByRefUseToMixed' => [ ' 'MixedReturnStatement' ], 'noCrashWhenComparingIllegitimateCallable' => [ ' ""; }', 'error_message' => 'InvalidReturnStatement', [], false, '7.4', ], 'detectImplicitVoidReturn' => [ 'getMessage(); } takesClosureReturningException( function () { echo "hello"; } );', 'error_message' => 'InvalidArgument' ], ]; } }