,error_levels?:string[]}> */ public function providerValidCodeParse() { 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' => 'null|numeric', ], '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' => [ ' [ ' $b */ function a($b): string { return $b["a"]; } a(["a" => "hello"]);', ], 'objectLikeKeyChecksAgainstObjectLike' => [ ' "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' => 'int|null', '$porte' => 'int|null', ], 'error_levels' => ['MixedReturnStatement', 'MixedInferredReturnType'], ], 'parseUrlComponent' => [ ' [ ' [ ' [], 'error_levels' => ['MixedMethodCall'], ], 'suppressError' => [ ' [ '$a' => 'false|string', ], ], 'printrOutput' => [ ' [ ' [ '$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' => [ ' [ ' [ '$a' => 'int', '$b' => 'int', '$c' => 'float', '$d' => 'float', '$e' => 'float|int', ], ], 'hashInit70' => [ ' 'resource', ], [], '7.1', ], 'hashInit71' => [ ' 'resource', ], [], '7.1', ], 'hashInit72' => [ ' 'HashContext', ], [], '7.2', ], 'hashInit73' => [ ' 'HashContext', ], [], '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 ); }', ], 'compactDefinedVariable' => [ ' [ ' "/", "expires" => 0, "httponly" => true, "secure" => true, "samesite" => "Lax" ] );', ], 'printrBadArg' => [ ' [ ' [ ' [ ' 'int', ] ], 'callUserFuncArray' => [ ' 'int', ] ], ]; } /** * @return iterable */ public function providerInvalidCodeParse() { 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 method 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', ], 'objectLikeKeyChecksAgainstDifferentObjectLike' => [ ' "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', ], 'usortInvalidComparison' => [ ' 'InvalidArgument', ], '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 method preg_match - expecting 2 but saw 1', ], 'compactUndefinedVariable' => [ ' 'UndefinedVariable', ], 'countCallableArrayShouldBeTwo' => [ ' 'TypeDoesNotContainType', ], 'coerceCallMapArgsInStrictMode' => [ ' 'TypeDoesNotContainType', ], 'noCrashOnEmptyArrayPush' => [ ' 'TooFewArguments', ], 'printOnlyString' => [ ' 'InvalidArgument', ], 'printReturns1' => [ ' 'TypeDoesNotContainType', ], ]; } }