[ ' 5, "b" => 12, "c" => null]); $e = array_filter( ["a" => 5, "b" => 12, "c" => null], function(?int $i): bool { return true; } );', 'assertions' => [ '$d' => 'array', '$e' => 'array', ], ], 'arrayFilterAdvanced' => [ ' 5, "b" => 12, "c" => null], function(?int $val, string $key): bool { return true; }, ARRAY_FILTER_USE_BOTH); $g = array_filter(["a" => 5, "b" => 12, "c" => null], function(string $val): bool { return true; }, ARRAY_FILTER_USE_KEY); $bar = "bar"; $foo = [ $bar => function (): string { return "baz"; }, ]; $foo = array_filter( $foo, function (string $key): bool { return $key === "bar"; }, ARRAY_FILTER_USE_KEY );', 'assertions' => [ '$f' => 'array', '$g' => 'array', ], ], 'typedArrayWithDefault' => [ ' $a */ function fooFoo(array $a = []): void { }', ], 'abs' => [ ' [ '$a' => 'int', '$b' => 'float', '$c' => 'numeric|null', ], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ], 'validDocblockParamDefault' => [ ' [ ' [ ' [ ' [ ' [ ' 1, "b" => 2]);', 'assertions' => [ '$a' => 'array', ], ], 'arrayKeysMixed' => [ ' 5]; $a = array_keys($b);', 'assertions' => [ '$a' => 'array', ], 'error_levels' => ['MixedArgument'], ], 'arrayValues' => [ ' 1, "b" => 2]);', 'assertions' => [ '$b' => 'array', ], ], 'arrayCombine' => [ ' [ '$c' => 'array', ], ], 'arrayMerge' => [ ' [ '$d' => 'array{0:string, 1:string, 2:string, 3:int, 4:int, 5:int}', ], ], 'arrayReverse' => [ ' [ '$d' => 'array', ], ], 'arrayReversePreserveKey' => [ ' [ '$d' => 'array', ], ], 'arrayDiff' => [ ' 5, "b" => 12], [5]);', 'assertions' => [ '$d' => 'array', ], ], 'arrayPopMixed' => [ ' 5, "c" => 6]; $a = array_pop($b);', 'assertions' => [ '$a' => 'mixed', '$b' => 'mixed', ], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ], 'uasort' => [ ' [], 'error_levels' => [ 'MixedArrayAccess', 'MixedArgument', 'MissingClosureParamType', 'MissingClosureReturnType', ], ], 'byRefAfterCallable' => [ ' [], 'error_levels' => [ 'MixedAssignment', 'MixedArrayAccess', 'RedundantConditionGivenDocblockType', ], ], 'ignoreNullablePregReplace' => [ ' [ ' "bar"]; extract($a); takesString($foo);', 'assertions' => [], 'error_levels' => [ 'MixedAssignment', 'MixedArrayAccess', 'MixedArgument', ], ], 'arrayMergeObjectLike' => [ ' $a * @return array */ function foo($a) { return $a; } $a1 = ["hi" => 3]; $a2 = ["bye" => 5]; $a3 = array_merge($a1, $a2); foo($a3);', 'assertions' => [ '$a3' => 'array{hi:int, bye:int}', ], ], 'goodByRef' => [ 'foo); fooFoo($b);', ], 'arrayRand' => [ ' "a", "y" => "b"]; $c = array_rand($vars); $d = $vars[$c]; $more_vars = ["a", "b"]; $e = array_rand($more_vars);', 'assertions' => [ '$vars' => 'array{x:string, y:string}', '$c' => 'string', '$d' => 'string', '$more_vars' => 'array{0:string, 1:string}', '$e' => 'int', ], ], 'arrayRandMultiple' => [ ' "a", "y" => "b"]; $b = 3; $c = array_rand($vars, 1); $d = array_rand($vars, 2); $e = array_rand($vars, 3); $f = array_rand($vars, $b);', 'assertions' => [ '$vars' => 'array{x:string, y:string}', '$c' => 'string', '$e' => 'array', '$f' => 'array|string', ], ], 'arrayKeysNoEmpty' => [ ' [], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ], 'compact' => [ ' [ ' $b */ function a($b): string { return $b["a"]; } a(["a" => "hello"]);', ], 'objectLikeKeyChecksAgainstObjectLike' => [ ' "hello"]);', ], 'getenv' => [ ' [ '$a' => 'array', '$b' => 'string|false', ], ], 'arrayPopIgnoreNullable' => [ ' $list */ function test(array $list) : void { while (!empty($list)) { $tmp = array_pop($list); expectsInt($tmp["item"]); } }', ], 'arrayFilterWithAssert' => [ ' [ '$a' => 'array', ], 'error_levels' => [ 'MissingClosureParamType', ], ], 'arrayFilterUseKey' => [ ' function (): string { return "baz"; }, ]; $foo = array_filter( $foo, function (string $key): bool { return $key === "bar"; }, ARRAY_FILTER_USE_KEY );', 'assertions' => [ '$foo' => 'array', ], ], 'ignoreFalsableCurrent' => [ ' [ ' [ ' [ ' [ '$foo' => 'float|int', ], ], 'arrayMapObjectLikeAndCallable' => [ ' 1, "key2"=> "2"]; $r = array_map("intval", $v); return $r; }', ], 'arrayMapObjectLikeAndClosure' => [ ' 1, "key2"=> "2"]; $r = array_map(function($i) : int { return intval($i);}, $v); return $r; }', 'assertions' => [], 'error_levels' => [ 'MissingClosureParamType', 'MixedTypeCoercion', ], ], 'arrayFilterGoodArgs' => [ ' [ ' [], 'error_levels' => ['UndefinedClass'], ], 'arrayFilterIgnoreMissingMethod' => [ ' [], 'error_levels' => ['UndefinedMethod'], ], 'validCallables' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ '$a' => 'string', ], ], 'key' => [ ' 1, "two" => 3]; $b = key($a); $c = $a[$b];', 'assertions' => [ '$b' => 'false|string', '$c' => 'int', ], ], 'explodeWithPossiblyFalse' => [ ' */ function exploder(string $s) : array { return explode(" ", $s); }', ], 'allowPossiblyUndefinedClassInClassExists' => [ ' [ ' 5, "b" => 12, "c" => null], function(?int $i) { return $_GET["a"]; } );', 'error_message' => 'MixedTypeCoercion', 'error_levels' => ['MissingClosureParamType', 'MissingClosureReturnType'], ], 'invalidScalarArgument' => [ ' 'InvalidScalarArgument', ], 'mixedArgument' => [ ' 'MixedArgument', 'error_levels' => ['MixedAssignment'], ], 'nullArgument' => [ ' 'NullArgument', ], 'tooFewArguments' => [ ' 'TooFewArguments', ], 'tooManyArguments' => [ ' 'TooManyArguments - src' . DIRECTORY_SEPARATOR . 'somefile.php:3 - Too many arguments for method fooFoo ' . '- expecting 1 but saw 2', ], 'tooManyArgumentsForConstructor' => [ ' 'TooManyArguments', ], 'typeCoercion' => [ ' 'TypeCoercion', ], 'arrayTypeCoercion' => [ ' 'TypeCoercion', ], 'duplicateParam' => [ ' 'DuplicateParam', 'error_levels' => ['MissingParamType'], ], 'invalidParamDefault' => [ ' 'InvalidParamDefault', ], 'invalidDocblockParamDefault' => [ ' 'InvalidParamDefault', ], 'badByRef' => [ ' 'InvalidPassByReference', ], 'badArrayByRef' => [ ' 'InvalidPassByReference', ], 'invalidArgAfterCallable' => [ ' 'InvalidScalarArgument', 'error_levels' => [ 'MixedAssignment', 'MixedArrayAccess', 'RedundantConditionGivenDocblockType', ], ], 'undefinedFunctionInArrayMap' => [ ' 'UndefinedFunction', ], 'objectLikeKeyChecksAgainstDifferentGeneric' => [ ' $b */ function a($b): int { return $b["a"]; } a(["a" => "hello"]);', 'error_message' => 'InvalidScalarArgument', ], 'objectLikeKeyChecksAgainstDifferentObjectLike' => [ ' "hello"]);', 'error_message' => 'InvalidArgument', ], 'possiblyNullFunctionCall' => [ ' 'PossiblyNullFunctionCall', ], 'possiblyInvalidFunctionCall' => [ ' 'PossiblyInvalidFunctionCall', ], 'arrayFilterBadArgs' => [ ' 'InvalidScalarArgument', ], 'arrayFilterTooFewArgs' => [ ' 'TooFewArguments', ], 'arrayMapBadArgs' => [ ' 'InvalidScalarArgument', ], 'arrayMapTooFewArgs' => [ ' 'TooFewArguments', ], 'arrayMapTooManyArgs' => [ ' 'TooManyArguments', ], 'varExportAssignmentToVoid' => [ ' 'AssignmentToVoid', ], 'explodeWithEmptyString' => [ ' 'FalsableReturnStatement', ], 'complainAboutArrayToIterable' => [ ' $p */ function takesIterableOfA(iterable $p): void {} takesIterableOfA([new B]); // should complain', 'error_message' => 'InvalidArgument', ], ]; } }