,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'preg_grep' => [ ' $strings * @return array */ function filter(array $strings): array { return preg_grep("/search/", $strings, PREG_GREP_INVERT); } ' ], 'typedArrayWithDefault' => [ ' $a */ function fooFoo(array $a = []): void { }', ], 'abs' => [ ' [ '$a' => 'int', '$b' => 'float', '$c' => 'float|int|null', ], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ], 'validDocblockParamDefault' => [ ' [ ' [ ' [ 'foo);', ], 'namespaced' => [ ' [ ' [ ' [ ' */ $a = []; $b = 5; if (count($a)) {}', ], 'noRedundantConditionAfterMixedOrEmptyArrayCountCheck' => [ ' [], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ], 'objectLikeArrayAssignmentInConditional' => [ ' [ ' [ ' */ public $arr = []; } /** @var array */ $replacement_stmts = []; if (!$replacement_stmts || !$replacement_stmts[0] instanceof B || count($replacement_stmts[0]->arr) > 1 ) { return null; } $b = $replacement_stmts[0]->arr;', 'assertions' => [ '$b' => 'array', ], ], 'countMoreThan0CanBeInverted' => [ ' 0) { exit; }', 'assertions' => [ '$a' => 'array', ], ], 'byRefAfterCallable' => [ ' [], 'error_levels' => [ 'MixedAssignment', 'MixedArrayAccess', 'RedundantConditionGivenDocblockType', ], ], 'ignoreNullablePregReplace' => [ ' [ ' "bar"]; extract($a); takesString($foo);', 'assertions' => [], 'error_levels' => [ 'MixedAssignment', 'MixedArrayAccess', 'MixedArgument', ], ], 'compact' => [ ' */ function test(): array { return compact(["val"]); }', ], 'objectLikeKeyChecksAgainstGeneric' => [ ' $b */ function a($b): string { return $b["a"]; } a(["a" => "hello"]);', ], 'objectLikeKeyChecksAgainstTKeyedArray' => [ ' "hello"]);', ], 'getenv' => [ ' [ '$a' => 'array', '$b' => 'false|string', ], ], 'ignoreFalsableFileGetContents' => [ ' [ ' [ ' [ ' [ ' [ ' [ '$a' => 'string', ], ], 'varExportConstFetch' => [ ' [ ' [ '$elements' => 'non-empty-list', ], ], 'explodeWithPositiveLimit' => [ ' [ '$elements' => 'non-empty-list', ], ], 'explodeWithNegativeLimit' => [ ' [ '$elements' => 'list', ], ], 'explodeWithDynamicLimit' => [ ' [ '$elements' => 'list', ], ], 'explodeWithDynamicDelimiter' => [ ' [ '$elements' => 'false|non-empty-list', ], ], 'explodeWithDynamicDelimiterAndPositiveLimit' => [ ' [ '$elements' => 'false|non-empty-list', ], ], 'explodeWithDynamicDelimiterAndNegativeLimit' => [ ' [ '$elements' => 'false|list', ], ], 'explodeWithDynamicDelimiterAndLimit' => [ ' [ '$elements' => 'false|list', ], ], 'explodeWithPossiblyFalse' => [ ' */ function exploder(string $d, string $s) : array { return explode($d, $s); }', ], 'allowPossiblyUndefinedClassInClassExists' => [ ' [ ' [], 'error_levels' => ['MixedMethodCall'], ], 'next' => [ ' [ '$n' => 'false|string', ], ], 'iteratorToArray' => [ ' */ function generator(): Generator { yield new stdClass; } $a = iterator_to_array(generator());', 'assertions' => [ '$a' => 'array', ], ], 'iteratorToArrayWithGetIterator' => [ ' */ public function getIterator() { yield 1 => "1"; } } $a = iterator_to_array(new C);', 'assertions' => [ '$a' => 'array', ], ], 'iteratorToArrayWithGetIteratorReturningList' => [ ' */ public function getIterator() { yield 1 => "1"; } } $a = iterator_to_array(new C, false);', 'assertions' => [ '$a' => 'list', ], ], 'strtrWithPossiblyFalseFirstArg' => [ ' $replace_pairs * @return string */ function strtr_wrapper($str, array $replace_pairs) { /** @psalm-suppress PossiblyFalseArgument */ return strtr($str, $replace_pairs); }', ], 'versionCompare' => [ ' [ '$a' => 'int', '$b' => 'bool', '$c' => 'bool', ], ], 'getTimeOfDay' => [ ' [ '$a' => 'float', '$b' => 'array', '$c' => 'array', ], ], 'parseUrlArray' => [ ' [ '$porta' => 'false|int|null', '$porte' => 'false|int|null', ], 'error_levels' => ['MixedReturnStatement', 'MixedInferredReturnType'], ], 'parseUrlComponent' => [ ' [ ' [ '$components' => 'array{fragment?: string, host?: string, pass?: string, path?: string, port?: int, query?: string, scheme?: string, user?: string}|false', '$scheme' => 'false|null|string', '$host' => 'false|null|string', '$port' => 'false|int|null', '$user' => 'false|null|string', '$pass' => 'false|null|string', '$path' => 'false|null|string', '$query' => 'false|null|string', '$fragment' => 'false|null|string', ], ], 'triggerUserError' => [ ' [ ' [], 'error_levels' => ['MixedMethodCall'], ], 'suppressError' => [ ' [ '$a' => 'false|string', ], ], 'echo' => [ ' [ ' [ ' [ '$a' => 'float', '$b' => 'string', '$c' => 'float|string', '$d' => 'string', ], ], 'filterVar' => [ ' ["default" => null]]); } function filterIntWithDefault(string $s) : int { return filter_var($s, FILTER_VALIDATE_INT, ["options" => ["default" => 5]]); } function filterBool(string $s) : bool { return filter_var($s, FILTER_VALIDATE_BOOLEAN); } function filterNullableBool(string $s) : ?bool { return filter_var($s, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } function filterNullableBoolWithFlagsArray(string $s) : ?bool { return filter_var($s, FILTER_VALIDATE_BOOLEAN, ["flags" => FILTER_NULL_ON_FAILURE]); } function filterFloat(string $s) : float { $filtered = filter_var($s, FILTER_VALIDATE_FLOAT); if ($filtered === false) { return 0.0; } return $filtered; } function filterFloatWithDefault(string $s) : float { return filter_var($s, FILTER_VALIDATE_FLOAT, ["options" => ["default" => 5.0]]); }', ], 'callVariableVar' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' ['UndefinedConstant', 'UnresolvableInclude'], ], 'noNamespaceClash' => [ ' [ ' 'resource', ], [], '7.1', ], 'hashInit71' => [ ' 'resource', ], [], '7.1', ], 'hashInit72' => [ ' 'HashContext|false', ], [], '7.2', ], 'hashInit73' => [ ' 'HashContext|false', ], [], '7.3', ], 'nullableByRef' => [ ' [ '[] */ public $arr = []; } (new Props)->arr[] = get_class(new C);', ], 'getClassVariable' => [ '[] */ public $arr = []; } (new Props)->arr[] = get_class($c_instance);', ], 'getClassAnonymousNewInstance' => [ '[] */ public $arr = []; } (new Props)->arr[] = get_class(new class implements I{});', ], 'getClassAnonymousVariable' => [ '[] */ public $arr = []; } (new Props)->arr[] = get_class($anon_instance);', ], 'mktime' => [ ' [ '$a' => 'false|int', '$b' => 'false|int', '$c' => 'int', ], ], 'PHP73-hrtime' => [ ' [ '$a' => 'int', '$b' => 'array{0: int, 1: int}', '$c' => 'array{0: int, 1: int}|int', '$d' => 'array{0: int, 1: int}', ], ], 'PHP73-hrtimeCanBeFloat' => [ ' [ ' [ '$a' => 'int', '$b' => 'int', '$c' => 'string', '$d' => 'int', '$e' => 'int', '$f' => 'int', ], ], 'minUnpackedArg' => [ ' [ '$f' => 'int', ], ], 'sscanf' => [ ' [ '$hours' => 'float|int|string', '$minutes' => 'float|int|string', '$seconds' => 'float|int|string', ], ], 'noImplicitAssignmentToStringFromMixedWithDocblockTypes' => [ ' [ ' [ '"); echo count($xml);', ], 'countableCallableArray' => [ ' [ ' [ ' [ ' [ ' [ ' [ 'bar(); }', ], 'functionExists' => [ ' [ ' [ ' [ ' [ ' [ '\n)/\', /** @param array $matches */ function (array $matches) : string { return $matches[1]; }, $s ); }', ], 'pregReplaceCallbackWithArray' => [ ' $matches[4], $ids ); };', 'assertions' => [], 'error_levels' => [], '7.4' ], 'compactDefinedVariable' => [ ' */ function foo(int $a, string $b, bool $c) : array { return compact("a", "b", "c"); }', ], 'PHP73-setCookiePhp73' => [ ' "/", "expires" => 0, "httponly" => true, "secure" => true, "samesite" => "Lax" ] );', ], 'printrBadArg' => [ ' [ ' [ ' [ ' 'int', ] ], 'callUserFuncArray' => [ ' 'int', ] ], 'dateTest' => [ ' 'numeric-string', '$m' => 'numeric-string', '$F' => 'string', '$y2' => 'numeric-string', '$F2' => 'string', '$F3' => 'false|string', ] ], 'sscanfReturnTypeWithTwoParameters' => [ ' 'list', ] ], 'sscanfReturnTypeWithMoreThanTwoParameters' => [ ' 'int', ] ], 'writeArgsAllowed' => [ ' [ ' [ ' $two */ function collectCommit(array $one, array $two) : void { if ($one && array_values($one) === array_values($two)) {} }' ], 'pregMatchAll' => [ '> */ function extractUsernames(string $input): array { preg_match_all(\'/([a-zA-Z])*/\', $input, $matches); return $matches; }' ], 'pregMatchAllOffsetCapture' => [ ' [ ' [ ' [ ' [ ' [ ' */ function foo(string $s) { return preg_split("/ /", $s, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); }' ], 'mbConvertEncodingWithArray' => [ ' $str * @return array */ function test2(array $str): array { return mb_convert_encoding($str, "UTF-8", "UTF-8"); }' ], 'getDebugType' => [ 'getMessage(); break; } }', [], [], '8.0' ], ]; } /** * @return iterable */ public function providerInvalidCodeParse(): iterable { return [ 'invalidScalarArgument' => [ ' 'InvalidScalarArgument', ], 'invalidArgumentWithDeclareStrictTypes' => [ ' 'InvalidArgument', ], 'builtinFunctioninvalidArgumentWithWeakTypes' => [ ' 'InvalidScalarArgument', ], 'builtinFunctioninvalidArgumentWithDeclareStrictTypes' => [ ' 'InvalidArgument', ], 'builtinFunctioninvalidArgumentWithDeclareStrictTypesInClass' => [ ' 'InvalidArgument', ], 'mixedArgument' => [ ' 'MixedArgument', 'error_levels' => ['MixedAssignment'], ], 'nullArgument' => [ ' 'NullArgument', ], 'tooFewArguments' => [ ' 'TooFewArguments', ], 'tooManyArguments' => [ ' 'TooManyArguments - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:21 - Too many arguments for fooFoo ' . '- expecting 1 but saw 2', ], 'tooManyArgumentsForConstructor' => [ ' 'TooManyArguments', ], 'typeCoercion' => [ ' 'ArgumentTypeCoercion', ], 'arrayTypeCoercion' => [ ' 'ArgumentTypeCoercion', ], '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', ], 'objectLikeKeyChecksAgainstDifferentTKeyedArray' => [ ' "hello"]);', 'error_message' => 'InvalidArgument', ], 'possiblyNullFunctionCall' => [ ' 'PossiblyNullFunctionCall', ], 'possiblyInvalidFunctionCall' => [ ' 'PossiblyInvalidFunctionCall', ], 'varExportAssignmentToVoid' => [ ' 'AssignmentToVoid', ], 'explodeWithEmptyString' => [ ' 'FalsableReturnStatement', ], 'complainAboutArrayToIterable' => [ ' $p */ function takesIterableOfA(iterable $p): void {} takesIterableOfA([new B]); // should complain', 'error_message' => 'InvalidArgument', ], 'complainAboutArrayToIterableSingleParam' => [ ' $p */ function takesIterableOfA(iterable $p): void {} takesIterableOfA([new B]); // should complain', 'error_message' => 'InvalidArgument', ], 'putInvalidTypeMessagesFirst' => [ ' 'InvalidArgument', ], 'getTypeInvalidValue' => [ ' 'TypeDoesNotContainType', ], 'rangeWithFloatStep' => [ ' 'InvalidScalarArgument', ], 'rangeWithFloatStart' => [ ' 'InvalidScalarArgument', ], 'duplicateFunction' => [ ' 'DuplicateFunction', ], 'duplicateCoreFunction' => [ ' 'DuplicateFunction', ], 'functionCallOnMixed' => [ ' 'MixedFunctionCall', ], 'iterableOfObjectCannotAcceptIterableOfInt' => [ ' $_p */ function accepts(iterable $_p): void {} /** @return iterable */ function iterable() { yield 1; } accepts(iterable());', 'error_message' => 'InvalidArgument', ], 'iterableOfObjectCannotAcceptTraversableOfInt' => [ ' $_p */ function accepts(iterable $_p): void {} /** @return Traversable */ function traversable() { yield 1; } accepts(traversable());', 'error_message' => 'InvalidArgument', ], 'iterableOfObjectCannotAcceptGeneratorOfInt' => [ ' $_p */ function accepts(iterable $_p): void {} /** @return Generator */ function generator() { yield 1; } accepts(generator());', 'error_message' => 'InvalidArgument', ], 'iterableOfObjectCannotAcceptArrayOfInt' => [ ' $_p */ function accepts(iterable $_p): void {} /** @return array */ function arr() { return [1]; } accepts(arr());', 'error_message' => 'InvalidArgument', ], 'nonNullableByRef' => [ ' 'NullReference', ], 'intCastByRef' => [ ' 'InvalidPassByReference', ], 'implicitAssignmentToStringFromMixed' => [ ' 'InvalidScalarArgument', ], 'tooFewArgsAccurateCount' => [ ' 'TooFewArguments - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:21 - Too few arguments for preg_match - expecting 2 but saw 1', ], 'compactUndefinedVariable' => [ ' */ function foo() : array { return compact("a", "b", "c"); }', 'error_message' => 'UndefinedVariable', ], 'countCallableArrayShouldBeTwo' => [ ' 'TypeDoesNotContainType', ], 'coerceCallMapArgsInStrictMode' => [ ' 'RedundantCondition', ], 'noCrashOnEmptyArrayPush' => [ ' 'TooFewArguments', ], 'printOnlyString' => [ ' 'InvalidArgument', ], 'printReturns1' => [ ' 'TypeDoesNotContainType', ], 'sodiumMemzeroNullifyString' => [ ' 'NullableReturnStatement' ], 'noCrashWithPattern' => [ ' 'UndefinedGlobalVariable' ], 'parseUrlPossiblyUndefined' => [ ' 'PossiblyUndefinedArrayOffset', ], 'parseUrlPossiblyUndefined2' => [ ' 'PossiblyUndefinedArrayOffset', ], 'strtolowerEmptiness' => [ ' 'RedundantConditionGivenDocblockType', ], 'strposNoSetFirstParam' => [ ' 'InvalidLiteralArgument', ], 'curlInitIsResourceFailsIn8x' => [ ' 'RedundantCondition', [], false, '8.0' ], 'maxCallWithArray' => [ ' 'ArgumentTypeCoercion', ], 'pregSplitNoEmpty' => [ ' 'InvalidReturnStatement' ], ]; } }