diff --git a/bin/generate.php b/bin/generate.php index 5bf628c8..ad27504e 100644 --- a/bin/generate.php +++ b/bin/generate.php @@ -8,9 +8,11 @@ */ use Webmozart\Assert\Bin\MixinGenerator; +use Webmozart\Assert\Bin\StaticAnalysisNonReturnGenerator; require_once __DIR__.'/../vendor/autoload.php'; file_put_contents(__DIR__.'/../src/Mixin.php', (new MixinGenerator())->generate()); +(new StaticAnalysisNonReturnGenerator(__DIR__.'/../tests/static-analysis'))->generate(); echo "Done."; diff --git a/bin/src/MixinGenerator.php b/bin/src/MixinGenerator.php index aa82e65e..c08c8e27 100644 --- a/bin/src/MixinGenerator.php +++ b/bin/src/MixinGenerator.php @@ -27,6 +27,8 @@ final class MixinGenerator private array $unsupportedMethods = [ 'nullOrNotInstanceOf', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotInstanceOf', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) + 'allIsNotInstanceOfAny', + 'allNullOrIsNotInstanceOfAny', 'nullOrNotEmpty', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotEmpty', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) 'allNotNull', // not supported by psalm (https://github.com/vimeo/psalm/issues/3443) @@ -76,6 +78,7 @@ private function namespace(): string $assert = new ReflectionClass(Assert::class); $namespace = sprintf("namespace %s;\n\n", $assert->getNamespaceName()); + $namespace .= sprintf("use %s;\n", \Closure::class); $namespace .= sprintf("use %s;\n", ArrayAccess::class); $namespace .= sprintf("use %s;\n", Countable::class); $namespace .= sprintf("use %s;\n", Throwable::class); @@ -231,11 +234,11 @@ private function assertion(ReflectionMethod $method, string $methodNameTemplate, } if ($parameterReflection->hasType()) { - if ($parameterReflection->name === 'value') { + if (count($parameters) === 1) { $parameterTypes[$parameterReflection->name] = 'mixed'; $nativeReturnType = match ($typeTemplate) { - '%s|null' => $this->reduceParameterType($parameterReflection->getType()), + '%s|null' => $this->nullableReturnType($method->getReturnType()), 'iterable<%s>' => 'iterable', 'iterable<%s|null>' => 'iterable', }; @@ -245,6 +248,12 @@ private function assertion(ReflectionMethod $method, string $methodNameTemplate, } } + // Ensure @template comes before @param, and @param values match function signature order + $parsedComment = $this->reorderAnnotations($parsedComment); + if (isset($parsedComment['param'])) { + $parsedComment['param'] = $this->reorderParamsBySignature($parsedComment['param'], $parameters); + } + if (in_array($newMethodName, $this->skipMethods, true)) { return null; } @@ -275,14 +284,24 @@ private function assertion(ReflectionMethod $method, string $methodNameTemplate, foreach ($values as $i => $value) { $parts = $this->splitDocLine($value); - if (('param' === $key || 'psalm-param' === $key) && isset($parts[1]) && isset($parameters[0]) && $parts[1] === '$'.$parameters[0] && 'mixed' !== $parts[0]) { + if ('param' === $key && isset($parts[1]) && isset($parameters[0]) && $parts[1] === '$'.$parameters[0] && 'mixed' !== $parts[0]) { $parts[0] = $this->applyTypeTemplate($parts[0], $typeTemplate); $values[$i] = \implode(' ', $parts); + + if ('mixed' === $phpdocReturnType) { + $phpdocReturnType = $parts[0]; + } } } - if ('psalm-return' === $key || 'return' === $key) { + if ('return' === $key) { + foreach ($values as $value) { + $parts = $this->splitDocLine($value); + if ('mixed' !== $parts[0]) { + $phpdocReturnType = $this->applyTypeTemplate($parts[0], $typeTemplate); + } + } continue; } @@ -322,6 +341,20 @@ private function assertion(ReflectionMethod $method, string $methodNameTemplate, } } + if ('mixed' === $phpdocReturnType) { + $returnType = $method->getReturnType(); + if ($returnType !== null) { + $returnTypeStr = $this->reduceParameterType($returnType); + if ('mixed' !== $returnTypeStr) { + $phpdocReturnType = $this->applyTypeTemplate($returnTypeStr, $typeTemplate); + } + } + } + + if ('mixed' === $phpdocReturnType && 'mixed' !== $nativeReturnType) { + $phpdocReturnType = $nativeReturnType; + } + $phpdocLines[] = '@return '.$phpdocReturnType; $phpdocLines[] = ''; @@ -351,7 +384,13 @@ private function reduceParameterType(ReflectionType $type): string return \implode('|', \array_map([$this, 'reduceParameterType'], $type->getTypes())); } - $type = Assert::isInstanceOf($type, ReflectionNamedType::class); + if (!$type instanceof ReflectionNamedType) { + throw new RuntimeException(sprintf( + 'Expected a "%s" instance, got "%s".', + ReflectionNamedType::class, + get_debug_type($type) + )); + } if ($type->getName() === 'mixed') { return $type->getName(); @@ -360,6 +399,19 @@ private function reduceParameterType(ReflectionType $type): string return ($type->allowsNull() ? '?' : '') . $type->getName(); } + private function nullableReturnType(?ReflectionType $type): string + { + if ($type === null) { + return 'mixed'; + } + $typeStr = $this->reduceParameterType($type); + if ($typeStr === 'mixed') { + return 'mixed'; + } + + return $typeStr.'|null'; + } + private function applyTypeTemplate(string $type, string $typeTemplate): string { $combinedType = sprintf($typeTemplate, $type); @@ -377,7 +429,7 @@ private function shouldSkipAnnotation(string $newMethodName, string $key): bool return false; } - return 'psalm-assert' === $key || 'psalm-return' === $key; + return 'psalm-assert' === $key; } /** @@ -557,6 +609,70 @@ private function splitDocLine(string $line): array return [trim($matches[1]), $matches[2], $matches[3] ?? null]; } + /** + * Ensures @template annotations appear before @param annotations. + * + * @param array> $annotations + * + * @return array> + */ + private function reorderAnnotations(array $annotations): array + { + $keys = array_keys($annotations); + $templatePos = array_search('template', $keys, true); + $paramPos = array_search('param', $keys, true); + + if ($templatePos === false || $paramPos === false || $templatePos < $paramPos) { + return $annotations; + } + + $result = []; + foreach ($annotations as $key => $values) { + if ($key === 'param') { + $result['template'] = $annotations['template']; + } + if ($key !== 'template') { + $result[$key] = $values; + } + } + + return $result; + } + + /** + * Reorders @param doc entries to match the function signature parameter order. + * + * @param list $paramDocs + * @param list $parameterNames + * + * @return list + */ + private function reorderParamsBySignature(array $paramDocs, array $parameterNames): array + { + $byVarName = []; + $withoutVarName = []; + + foreach ($paramDocs as $doc) { + $parts = $this->splitDocLine($doc); + if (isset($parts[1])) { + $byVarName[$parts[1]] = $doc; + } else { + $withoutVarName[] = $doc; + } + } + + $ordered = []; + foreach ($parameterNames as $name) { + $key = '$'.$name; + if (isset($byVarName[$key])) { + $ordered[] = $byVarName[$key]; + unset($byVarName[$key]); + } + } + + return array_merge($ordered, array_values($byVarName), $withoutVarName); + } + /** * @psalm-return list * diff --git a/bin/src/StaticAnalysisNonReturnGenerator.php b/bin/src/StaticAnalysisNonReturnGenerator.php new file mode 100644 index 00000000..45f66000 --- /dev/null +++ b/bin/src/StaticAnalysisNonReturnGenerator.php @@ -0,0 +1,117 @@ +targetDirectory(); + + if (!is_dir($targetDirectory) && !mkdir($targetDirectory, 0777, true) && !is_dir($targetDirectory)) { + throw new RuntimeException(sprintf('Could not create "%s".', $targetDirectory)); + } + + foreach ($this->generatedFiles() as $targetFile => $content) { + if (false === file_put_contents($targetFile, $content)) { + throw new RuntimeException(sprintf('Could not write "%s".', $targetFile)); + } + } + } + + /** + * @return array + */ + public function generatedFiles(): array + { + $generatedFiles = []; + + foreach ($this->sourceFiles() as $sourceFile) { + $content = file_get_contents($sourceFile); + if (false === $content) { + throw new RuntimeException(sprintf('Could not read "%s".', $sourceFile)); + } + + $generatedFiles[$this->targetDirectory().'/'.basename($sourceFile)] = $this->generateFileContent($content, $sourceFile); + } + + return $generatedFiles; + } + + public function generateFileContent(string $content, string $sourceFile): string + { + $content = str_replace(self::SOURCE_NAMESPACE, self::TARGET_NAMESPACE, $content); + + $replacementCount = 0; + $generatedContent = preg_replace_callback( + '/^(\s*)return Assert::([A-Za-z0-9_]+)\((\$[A-Za-z_][A-Za-z0-9_]*)([^;\n]*)\);$/m', + static function (array $matches): string { + return sprintf( + "%sAssert::%s(%s%s);\n\n%sreturn %s;", + $matches[1], + $matches[2], + $matches[3], + $matches[4], + $matches[1], + $matches[3] + ); + }, + $content, + -1, + $replacementCount + ); + + if (null === $generatedContent) { + throw new RuntimeException(sprintf('Could not generate non-return static analysis test from "%s".', $sourceFile)); + } + + $generatedContent = preg_replace("/;\n{3,}([ \t]+return )/", ";\n\n$1", $generatedContent); + if (null === $generatedContent) { + throw new RuntimeException(sprintf('Could not normalize non-return static analysis test from "%s".', $sourceFile)); + } + + $expectedReplacementCount = substr_count($content, 'return Assert::'); + if ($replacementCount !== $expectedReplacementCount) { + throw new RuntimeException(sprintf( + 'Expected to replace %d return assertions in "%s", replaced %d.', + $expectedReplacementCount, + $sourceFile, + (int) $replacementCount + )); + } + + return $generatedContent; + } + + /** + * @return list + */ + private function sourceFiles(): array + { + $files = glob($this->staticAnalysisDirectory.'/assert-*.php'); + if (false === $files) { + throw new RuntimeException(sprintf('Could not scan "%s".', $this->staticAnalysisDirectory)); + } + + sort($files); + + return $files; + } + + private function targetDirectory(): string + { + return $this->staticAnalysisDirectory.'/non-return'; + } +} diff --git a/composer.json b/composer.json index 18f625ce..f89a6860 100644 --- a/composer.json +++ b/composer.json @@ -40,8 +40,12 @@ } }, "extra": { + "psalm": { + "pluginClass": "Webmozart\\Assert\\PsalmPlugin" + }, "branch-alias": { - "dev-feature/2-0": "2.0-dev" + "dev-feature/2-0": "2.0-dev", + "dev-master": "2.0-dev" } }, "scripts": { @@ -63,5 +67,8 @@ "cs-fix": "./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix", "static-analysis": "./tools/psalm/vendor/bin/psalm --threads=4 --root=$(pwd)", "test": "./tools/phpunit/vendor/bin/phpunit" + }, + "require-dev": { + "vimeo/psalm": "^6" } } diff --git a/psalm.xml b/psalm.xml index c5c24f84..92fb8972 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ + + + + diff --git a/src/Assert.php b/src/Assert.php index 9a484c8f..160f5037 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -62,7 +62,7 @@ public static function string(mixed $value, string|callable $message = ''): stri * @psalm-assert non-empty-string $value * @param string|callable():string $message * - * @psalm-return non-empty-string + * @return non-empty-string * * @throws InvalidArgumentException */ @@ -124,7 +124,7 @@ public static function integerish(mixed $value, string|callable $message = ''): * * @param string|callable():string $message * - * @psalm-return positive-int + * @return positive-int * * @throws InvalidArgumentException */ @@ -148,7 +148,7 @@ public static function positiveInteger(mixed $value, string|callable $message = * @psalm-assert non-negative-int $value * @param string|callable():string $message * - * @psalm-return non-negative-int + * @return non-negative-int * * @throws InvalidArgumentException */ @@ -172,7 +172,7 @@ public static function notNegativeInteger(mixed $value, string|callable $message * @psalm-assert negative-int $value * @param string|callable():string $message * - * @psalm-return negative-int + * @return negative-int * * @throws InvalidArgumentException */ @@ -242,7 +242,7 @@ public static function numeric(mixed $value, string|callable $message = ''): int * * @param string|callable():string $message * - * @psalm-return positive-int|0 + * @return positive-int|0 * * @throws InvalidArgumentException */ @@ -332,7 +332,7 @@ public static function object(mixed $value, string|callable $message = ''): obje * * @param string|callable():string $message * - * @psalm-return object|string + * @return object|string * * @throws InvalidArgumentException */ @@ -366,7 +366,7 @@ public static function objectish(mixed $value, string|callable $message = ''): o * * @see https://www.php.net/manual/en/function.get-resource-type.php * - * @psalm-return resource + * @return resource * * @throws InvalidArgumentException */ @@ -537,7 +537,7 @@ public static function isIterable(mixed $value, string|callable $message = ''): * @psalm-assert T $value * * @param string|callable():string $message - * @psalm-param class-string $class + * @param class-string $class * * @return T * @@ -565,9 +565,7 @@ public static function isInstanceOf(mixed $value, mixed $class, string|callable * @psalm-assert object $value * * @param string|callable():string $message - * @psalm-param class-string $class - * - * @return !T + * @param class-string $class * * @throws InvalidArgumentException */ @@ -592,7 +590,7 @@ public static function notInstanceOf(mixed $value, mixed $class, string|callable * * @psalm-assert T $value * - * @param T $value + * @param array> $classes * @param string|callable():string $message * * @return T @@ -622,7 +620,7 @@ public static function isInstanceOfAny(mixed $value, mixed $classes, string|call /** * @template T * - * @psalm-assert T $value + * @psalm-assert object|class-string $value * * @param T $value * @param string|callable():string $message @@ -659,8 +657,9 @@ public static function isNotInstanceOfAny(mixed $value, mixed $classes, string|c * @psalm-assert T|class-string $value * * @param string|callable():string $message + * @param class-string $class * - * @return T + * @return T|class-string * * @throws InvalidArgumentException */ @@ -690,7 +689,7 @@ public static function isAOf(mixed $value, mixed $class, string|callable $messag * @param T $value * @param string|callable():string $message * - * @return T + * @return object|class-string * * @throws InvalidArgumentException */ @@ -714,11 +713,14 @@ public static function isNotA(mixed $value, mixed $class, string|callable $messa /** * @psalm-pure * - * @param object|string $value - * @param string[] $classes + * @psalm-assert T $value + * + * @template T as object + * + * @param array> $classes * @param string|callable():string $message - * @psalm-param array $classes * + * @return T * @throws InvalidArgumentException */ public static function isAnyOf(mixed $value, mixed $classes, string|callable $message = ''): object|string @@ -749,7 +751,7 @@ public static function isAnyOf(mixed $value, mixed $classes, string|callable $me * * @param string|callable():string $message * - * @psalm-return empty + * @return empty * * @throws InvalidArgumentException */ @@ -773,8 +775,6 @@ public static function isEmpty(mixed $value, string|callable $message = ''): mix * * @param string|callable():string $message * - * @psalm-return !empty - * * @throws InvalidArgumentException */ public static function notEmpty(mixed $value, string|callable $message = ''): mixed @@ -819,8 +819,9 @@ public static function null(mixed $value, string|callable $message = ''): null * * @param string|callable():string $message * - * @psalm-return !null - * + * @template T + * @param T|null $value + * @return T * @throws InvalidArgumentException */ public static function notNull(mixed $value, string|callable $message = ''): mixed @@ -886,6 +887,9 @@ public static function false(mixed $value, string|callable $message = ''): false * * @param string|callable():string $message * + * @template T + * @param T|false $value + * @return T * @throws InvalidArgumentException */ public static function notFalse(mixed $value, string|callable $message = ''): mixed @@ -904,7 +908,7 @@ public static function notFalse(mixed $value, string|callable $message = ''): mi * @psalm-pure * * @param string|callable():string $message - * @psalm-param string $value + * @param string $value * * @throws InvalidArgumentException */ @@ -927,7 +931,7 @@ public static function ip(mixed $value, string|callable $message = ''): string * @psalm-pure * * @param string|callable():string $message - * @psalm-param string $value + * @param string $value * * @throws InvalidArgumentException */ @@ -950,7 +954,7 @@ public static function ipv4(mixed $value, string|callable $message = ''): string * @psalm-pure * * @param string|callable():string $message - * @psalm-param string $value + * @param string $value * * @throws InvalidArgumentException */ @@ -973,7 +977,7 @@ public static function ipv6(mixed $value, string|callable $message = ''): string * @psalm-pure * * @param string|callable():string $message - * @psalm-param string $value + * @param string $value * * @throws InvalidArgumentException */ @@ -996,6 +1000,8 @@ public static function email(mixed $value, string|callable $message = ''): strin * Does non-strict comparisons on the items, so ['3', 3] will not pass the assertion. * Note: objects with identical properties are also considered equal. * + * @psalm-assert array $values + * * @param string|callable():string $message * * @throws InvalidArgumentException @@ -1647,6 +1653,8 @@ public static function alnum(mixed $value, string|callable $message = ''): strin * * @param string|callable():string $message * + * @return lowercase-string + * * @throws InvalidArgumentException */ public static function lower(mixed $value, string|callable $message = ''): string @@ -1672,7 +1680,7 @@ public static function lower(mixed $value, string|callable $message = ''): strin /** * @psalm-pure * - * @psalm-assert !lowercase-string $value + * @psalm-assert string $value * * @param string|callable():string $message * @@ -1911,6 +1919,8 @@ public static function writable(mixed $value, string|callable $message = ''): st * * @param string|callable():string $message * + * @return class-string + * * @throws InvalidArgumentException */ public static function classExists(mixed $value, string|callable $message = ''): string @@ -1964,6 +1974,8 @@ public static function subclassOf(mixed $value, mixed $class, string|callable $m * * @param string|callable():string $message * + * @return class-string + * * @throws InvalidArgumentException */ public static function interfaceExists(mixed $value, string|callable $message = ''): string @@ -1988,10 +2000,11 @@ public static function interfaceExists(mixed $value, string|callable $message = * * @psalm-assert class-string|ExpectedType $value * - * @param class-string|ExpectedType $value * @param class-string $interface * @param string|callable():string $message * + * @return class-string|ExpectedType + * * @throws InvalidArgumentException */ public static function implementsInterface(mixed $value, mixed $interface, string|callable $message = ''): object|string @@ -2040,9 +2053,8 @@ public static function propertyExists(mixed $classOrObject, mixed $property, str /** * @psalm-pure * - * @param string|object $classOrObject + * @param class-string|object $classOrObject * @param string|callable():string $message - * @psalm-param class-string|object $classOrObject * * @throws InvalidArgumentException */ @@ -2062,9 +2074,8 @@ public static function propertyNotExists(mixed $classOrObject, mixed $property, /** * @psalm-pure * - * @param string|object $classOrObject + * @param class-string|object $classOrObject * @param string|callable():string $message - * @psalm-param class-string|object $classOrObject * * @throws InvalidArgumentException */ @@ -2086,9 +2097,8 @@ public static function methodExists(mixed $classOrObject, mixed $method, string| /** * @psalm-pure * - * @param string|object $classOrObject + * @param class-string|object $classOrObject * @param string|callable():string $message - * @psalm-param class-string|object $classOrObject * * @throws InvalidArgumentException */ @@ -2277,7 +2287,7 @@ public static function countBetween(mixed $array, mixed $min, mixed $max, string * * @param string|callable():string $message * - * @psalm-return list + * @return list * * @throws InvalidArgumentException */ @@ -2300,7 +2310,7 @@ public static function isList(mixed $array, string|callable $message = ''): arra * * @param string|callable():string $message * - * @psalm-return non-empty-list + * @return non-empty-list * * @throws InvalidArgumentException */ @@ -2341,9 +2351,8 @@ public static function isMap(mixed $array, string|callable $message = ''): array } /** - * @psalm-assert callable $callable + * @param callable $callable * - * @param Closure|callable $callable * @param string|callable():string $message * * @return Closure|callable-string @@ -2369,9 +2378,8 @@ public static function isStatic(mixed $callable, string|callable $message = ''): } /** - * @psalm-assert callable $callable + * @param callable $callable * - * @param Closure|callable $callable * @param string|callable():string $message * * @return Closure|callable-string @@ -2407,7 +2415,7 @@ public static function notStatic(mixed $callable, string|callable $message = '') * @param array $array * @param string|callable():string $message * - * @return array + * @return non-empty-array * * @throws InvalidArgumentException */ @@ -2452,7 +2460,7 @@ public static function uuid(mixed $value, string|callable $message = ''): string /** * @param string|callable():string $message - * @psalm-param class-string $class + * @param class-string $class * * @throws InvalidArgumentException */ diff --git a/src/Mixin.php b/src/Mixin.php index bab3889d..b001dc72 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4,6 +4,7 @@ namespace Webmozart\Assert; +use Closure; use ArrayAccess; use Countable; use Throwable; @@ -25,7 +26,7 @@ trait Mixin * * @throws InvalidArgumentException */ - public static function nullOrString(mixed $value, callable|string $message = ''): mixed + public static function nullOrString(mixed $value, callable|string $message = ''): string|null { null === $value || static::string($value, $message); @@ -87,7 +88,7 @@ public static function allNullOrString(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrStringNotEmpty(mixed $value, callable|string $message = ''): mixed + public static function nullOrStringNotEmpty(mixed $value, callable|string $message = ''): string|null { null === $value || static::stringNotEmpty($value, $message); @@ -149,7 +150,7 @@ public static function allNullOrStringNotEmpty(mixed $value, callable|string $me * * @throws InvalidArgumentException */ - public static function nullOrInteger(mixed $value, callable|string $message = ''): mixed + public static function nullOrInteger(mixed $value, callable|string $message = ''): int|null { null === $value || static::integer($value, $message); @@ -211,7 +212,7 @@ public static function allNullOrInteger(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrIntegerish(mixed $value, callable|string $message = ''): mixed + public static function nullOrIntegerish(mixed $value, callable|string $message = ''): string|int|float|null { null === $value || static::integerish($value, $message); @@ -273,7 +274,7 @@ public static function allNullOrIntegerish(mixed $value, callable|string $messag * * @throws InvalidArgumentException */ - public static function nullOrPositiveInteger(mixed $value, callable|string $message = ''): mixed + public static function nullOrPositiveInteger(mixed $value, callable|string $message = ''): int|null { null === $value || static::positiveInteger($value, $message); @@ -335,7 +336,7 @@ public static function allNullOrPositiveInteger(mixed $value, callable|string $m * * @throws InvalidArgumentException */ - public static function nullOrNotNegativeInteger(mixed $value, callable|string $message = ''): mixed + public static function nullOrNotNegativeInteger(mixed $value, callable|string $message = ''): int|null { null === $value || static::notNegativeInteger($value, $message); @@ -397,7 +398,7 @@ public static function allNullOrNotNegativeInteger(mixed $value, callable|string * * @throws InvalidArgumentException */ - public static function nullOrNegativeInteger(mixed $value, callable|string $message = ''): mixed + public static function nullOrNegativeInteger(mixed $value, callable|string $message = ''): int|null { null === $value || static::negativeInteger($value, $message); @@ -459,7 +460,7 @@ public static function allNullOrNegativeInteger(mixed $value, callable|string $m * * @throws InvalidArgumentException */ - public static function nullOrFloat(mixed $value, callable|string $message = ''): mixed + public static function nullOrFloat(mixed $value, callable|string $message = ''): float|null { null === $value || static::float($value, $message); @@ -521,7 +522,7 @@ public static function allNullOrFloat(mixed $value, callable|string $message = ' * * @throws InvalidArgumentException */ - public static function nullOrNumeric(mixed $value, callable|string $message = ''): mixed + public static function nullOrNumeric(mixed $value, callable|string $message = ''): string|int|float|null { null === $value || static::numeric($value, $message); @@ -583,7 +584,7 @@ public static function allNullOrNumeric(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrNatural(mixed $value, callable|string $message = ''): mixed + public static function nullOrNatural(mixed $value, callable|string $message = ''): int|null { null === $value || static::natural($value, $message); @@ -645,7 +646,7 @@ public static function allNullOrNatural(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrBoolean(mixed $value, callable|string $message = ''): mixed + public static function nullOrBoolean(mixed $value, callable|string $message = ''): bool|null { null === $value || static::boolean($value, $message); @@ -707,7 +708,7 @@ public static function allNullOrBoolean(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrScalar(mixed $value, callable|string $message = ''): mixed + public static function nullOrScalar(mixed $value, callable|string $message = ''): string|int|float|bool|null { null === $value || static::scalar($value, $message); @@ -769,7 +770,7 @@ public static function allNullOrScalar(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrObject(mixed $value, callable|string $message = ''): mixed + public static function nullOrObject(mixed $value, callable|string $message = ''): object|null { null === $value || static::object($value, $message); @@ -831,7 +832,7 @@ public static function allNullOrObject(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrObjectish(mixed $value, callable|string $message = ''): mixed + public static function nullOrObjectish(mixed $value, callable|string $message = ''): object|string|null { null === $value || static::objectish($value, $message); @@ -961,7 +962,7 @@ public static function allNullOrResource(mixed $value, ?string $type = null, cal * * @throws InvalidArgumentException */ - public static function nullOrIsCallable(mixed $value, callable|string $message = ''): mixed + public static function nullOrIsCallable(mixed $value, callable|string $message = ''): callable|null { null === $value || static::isCallable($value, $message); @@ -1023,7 +1024,7 @@ public static function allNullOrIsCallable(mixed $value, callable|string $messag * * @throws InvalidArgumentException */ - public static function nullOrIsArray(mixed $value, callable|string $message = ''): mixed + public static function nullOrIsArray(mixed $value, callable|string $message = ''): array|null { null === $value || static::isArray($value, $message); @@ -1085,7 +1086,7 @@ public static function allNullOrIsArray(mixed $value, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrIsArrayAccessible(mixed $value, callable|string $message = ''): mixed + public static function nullOrIsArrayAccessible(mixed $value, callable|string $message = ''): ArrayAccess|array|null { null === $value || static::isArrayAccessible($value, $message); @@ -1147,7 +1148,7 @@ public static function allNullOrIsArrayAccessible(mixed $value, callable|string * * @throws InvalidArgumentException */ - public static function nullOrIsCountable(mixed $value, callable|string $message = ''): mixed + public static function nullOrIsCountable(mixed $value, callable|string $message = ''): Countable|array|null { null === $value || static::isCountable($value, $message); @@ -1209,7 +1210,7 @@ public static function allNullOrIsCountable(mixed $value, callable|string $messa * * @throws InvalidArgumentException */ - public static function nullOrIsIterable(mixed $value, callable|string $message = ''): mixed + public static function nullOrIsIterable(mixed $value, callable|string $message = ''): iterable|null { null === $value || static::isIterable($value, $message); @@ -1266,15 +1267,14 @@ public static function allNullOrIsIterable(mixed $value, callable|string $messag * @template T of object * @psalm-assert T|null $value * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * * @return T|null * * @throws InvalidArgumentException */ - public static function nullOrIsInstanceOf(mixed $value, mixed $class, callable|string $message = ''): mixed + public static function nullOrIsInstanceOf(mixed $value, mixed $class, callable|string $message = ''): object|null { null === $value || static::isInstanceOf($value, $class, $message); @@ -1287,10 +1287,9 @@ public static function nullOrIsInstanceOf(mixed $value, mixed $class, callable|s * @template T of object * @psalm-assert iterable $value * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * * @return iterable * * @throws InvalidArgumentException @@ -1312,10 +1311,9 @@ public static function allIsInstanceOf(mixed $value, mixed $class, callable|stri * @template T of object * @psalm-assert iterable $value * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * * @return iterable * * @throws InvalidArgumentException @@ -1334,15 +1332,14 @@ public static function allNullOrIsInstanceOf(mixed $value, mixed $class, callabl /** * @template T of object * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * - * @return mixed + * @return object|null * * @throws InvalidArgumentException */ - public static function nullOrNotInstanceOf(mixed $value, mixed $class, callable|string $message = ''): mixed + public static function nullOrNotInstanceOf(mixed $value, mixed $class, callable|string $message = ''): object|null { null === $value || static::notInstanceOf($value, $class, $message); @@ -1352,11 +1349,10 @@ public static function nullOrNotInstanceOf(mixed $value, mixed $class, callable| /** * @template T of object * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -1375,10 +1371,9 @@ public static function allNotInstanceOf(mixed $value, mixed $class, callable|str * @template T of object * @psalm-assert iterable $value * + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * * @return iterable * * @throws InvalidArgumentException @@ -1398,14 +1393,14 @@ public static function allNullOrNotInstanceOf(mixed $value, mixed $class, callab * @template T of object * @psalm-assert T|null $value * - * @param T|null $value + * @param array> $classes * @param string|callable():string $message * * @return T|null * * @throws InvalidArgumentException */ - public static function nullOrIsInstanceOfAny(mixed $value, mixed $classes, callable|string $message = ''): mixed + public static function nullOrIsInstanceOfAny(mixed $value, mixed $classes, callable|string $message = ''): object|null { null === $value || static::isInstanceOfAny($value, $classes, $message); @@ -1416,7 +1411,7 @@ public static function nullOrIsInstanceOfAny(mixed $value, mixed $classes, calla * @template T of object * @psalm-assert iterable $value * - * @param iterable $value + * @param array> $classes * @param string|callable():string $message * * @return iterable @@ -1438,7 +1433,7 @@ public static function allIsInstanceOfAny(mixed $value, mixed $classes, callable * @template T of object * @psalm-assert iterable $value * - * @param iterable $value + * @param array> $classes * @param string|callable():string $message * * @return iterable @@ -1458,7 +1453,7 @@ public static function allNullOrIsInstanceOfAny(mixed $value, mixed $classes, ca /** * @template T - * @psalm-assert T|null $value + * @psalm-assert object|class-string|null $value * * @param T|null $value * @param string|callable():string $message @@ -1476,7 +1471,6 @@ public static function nullOrIsNotInstanceOfAny(mixed $value, mixed $classes, ca /** * @template T - * @psalm-assert iterable $value * * @param iterable $value * @param string|callable():string $message @@ -1498,7 +1492,6 @@ public static function allIsNotInstanceOfAny(mixed $value, mixed $classes, calla /** * @template T - * @psalm-assert iterable $value * * @param iterable $value * @param string|callable():string $message @@ -1524,13 +1517,14 @@ public static function allNullOrIsNotInstanceOfAny(mixed $value, mixed $classes, * @template T of object * @psalm-assert T|class-string|null $value * + * @param class-string $class * @param string|callable():string $message * * @return T|class-string|null * * @throws InvalidArgumentException */ - public static function nullOrIsAOf(mixed $value, mixed $class, callable|string $message = ''): mixed + public static function nullOrIsAOf(mixed $value, mixed $class, callable|string $message = ''): object|string|null { null === $value || static::isAOf($value, $class, $message); @@ -1543,6 +1537,7 @@ public static function nullOrIsAOf(mixed $value, mixed $class, callable|string $ * @template T of object * @psalm-assert iterable> $value * + * @param class-string $class * @param string|callable():string $message * * @return iterable> @@ -1566,6 +1561,7 @@ public static function allIsAOf(mixed $value, mixed $class, callable|string $mes * @template T of object * @psalm-assert iterable|null> $value * + * @param class-string $class * @param string|callable():string $message * * @return iterable|null> @@ -1591,11 +1587,11 @@ public static function allNullOrIsAOf(mixed $value, mixed $class, callable|strin * @param T|null $value * @param string|callable():string $message * - * @return mixed + * @return object|class-string|null * * @throws InvalidArgumentException */ - public static function nullOrIsNotA(mixed $value, mixed $class, callable|string $message = ''): mixed + public static function nullOrIsNotA(mixed $value, mixed $class, callable|string $message = ''): object|string|null { null === $value || static::isNotA($value, $class, $message); @@ -1610,7 +1606,7 @@ public static function nullOrIsNotA(mixed $value, mixed $class, callable|string * @param iterable $value * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -1652,17 +1648,18 @@ public static function allNullOrIsNotA(mixed $value, mixed $class, callable|stri /** * @psalm-pure * - * @param object|string|null $value - * @param string[] $classes - * @param string|callable():string $message + * @psalm-assert T|null $value * - * @psalm-param array $classes + * @template T as object * - * @return mixed + * @param array> $classes + * @param string|callable():string $message + * + * @return T|null * * @throws InvalidArgumentException */ - public static function nullOrIsAnyOf(mixed $value, mixed $classes, callable|string $message = ''): mixed + public static function nullOrIsAnyOf(mixed $value, mixed $classes, callable|string $message = ''): object|string|null { null === $value || static::isAnyOf($value, $classes, $message); @@ -1672,13 +1669,14 @@ public static function nullOrIsAnyOf(mixed $value, mixed $classes, callable|stri /** * @psalm-pure * - * @param iterable $value - * @param string[] $classes - * @param string|callable():string $message + * @psalm-assert iterable $value * - * @psalm-param array $classes + * @template T as object * - * @return mixed + * @param array> $classes + * @param string|callable():string $message + * + * @return iterable * * @throws InvalidArgumentException */ @@ -1696,13 +1694,14 @@ public static function allIsAnyOf(mixed $value, mixed $classes, callable|string /** * @psalm-pure * - * @param iterable $value - * @param string[] $classes - * @param string|callable():string $message + * @psalm-assert iterable $value * - * @psalm-param array $classes + * @template T as object * - * @return mixed + * @param array> $classes + * @param string|callable():string $message + * + * @return iterable * * @throws InvalidArgumentException */ @@ -1800,7 +1799,7 @@ public static function nullOrNotEmpty(mixed $value, callable|string $message = ' * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -1862,9 +1861,12 @@ public static function allNull(mixed $value, callable|string $message = ''): ite /** * @psalm-pure * + * @template T + * + * @param iterable $value * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -1890,7 +1892,7 @@ public static function allNotNull(mixed $value, callable|string $message = ''): * * @throws InvalidArgumentException */ - public static function nullOrTrue(mixed $value, callable|string $message = ''): mixed + public static function nullOrTrue(mixed $value, callable|string $message = ''): true|null { null === $value || static::true($value, $message); @@ -1952,7 +1954,7 @@ public static function allNullOrTrue(mixed $value, callable|string $message = '' * * @throws InvalidArgumentException */ - public static function nullOrFalse(mixed $value, callable|string $message = ''): mixed + public static function nullOrFalse(mixed $value, callable|string $message = ''): false|null { null === $value || static::false($value, $message); @@ -2006,9 +2008,12 @@ public static function allNullOrFalse(mixed $value, callable|string $message = ' /** * @psalm-pure * + * @template T + * + * @param T|false|null $value * @param string|callable():string $message * - * @return mixed + * @return T|null * * @throws InvalidArgumentException */ @@ -2022,9 +2027,12 @@ public static function nullOrNotFalse(mixed $value, callable|string $message = ' /** * @psalm-pure * + * @template T + * + * @param iterable $value * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2044,9 +2052,12 @@ public static function allNotFalse(mixed $value, callable|string $message = ''): * * @psalm-assert iterable $value * + * @template T + * + * @param iterable $value * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ @@ -2064,15 +2075,14 @@ public static function allNullOrNotFalse(mixed $value, callable|string $message /** * @psalm-pure * + * @param string|null $value * @param string|callable():string $message * - * @psalm-param string|null $value - * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrIp(mixed $value, callable|string $message = ''): mixed + public static function nullOrIp(mixed $value, callable|string $message = ''): string|null { null === $value || static::ip($value, $message); @@ -2082,11 +2092,10 @@ public static function nullOrIp(mixed $value, callable|string $message = ''): mi /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2104,11 +2113,10 @@ public static function allIp(mixed $value, callable|string $message = ''): itera /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2126,15 +2134,14 @@ public static function allNullOrIp(mixed $value, callable|string $message = ''): /** * @psalm-pure * + * @param string|null $value * @param string|callable():string $message * - * @psalm-param string|null $value - * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrIpv4(mixed $value, callable|string $message = ''): mixed + public static function nullOrIpv4(mixed $value, callable|string $message = ''): string|null { null === $value || static::ipv4($value, $message); @@ -2144,11 +2151,10 @@ public static function nullOrIpv4(mixed $value, callable|string $message = ''): /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2166,11 +2172,10 @@ public static function allIpv4(mixed $value, callable|string $message = ''): ite /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2188,15 +2193,14 @@ public static function allNullOrIpv4(mixed $value, callable|string $message = '' /** * @psalm-pure * + * @param string|null $value * @param string|callable():string $message * - * @psalm-param string|null $value - * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrIpv6(mixed $value, callable|string $message = ''): mixed + public static function nullOrIpv6(mixed $value, callable|string $message = ''): string|null { null === $value || static::ipv6($value, $message); @@ -2206,11 +2210,10 @@ public static function nullOrIpv6(mixed $value, callable|string $message = ''): /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2228,11 +2231,10 @@ public static function allIpv6(mixed $value, callable|string $message = ''): ite /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2250,15 +2252,14 @@ public static function allNullOrIpv6(mixed $value, callable|string $message = '' /** * @psalm-pure * + * @param string|null $value * @param string|callable():string $message * - * @psalm-param string|null $value - * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrEmail(mixed $value, callable|string $message = ''): mixed + public static function nullOrEmail(mixed $value, callable|string $message = ''): string|null { null === $value || static::email($value, $message); @@ -2268,11 +2269,10 @@ public static function nullOrEmail(mixed $value, callable|string $message = ''): /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2290,11 +2290,10 @@ public static function allEmail(mixed $value, callable|string $message = ''): it /** * @psalm-pure * + * @param iterable $value * @param string|callable():string $message * - * @psalm-param iterable $value - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2310,13 +2309,15 @@ public static function allNullOrEmail(mixed $value, callable|string $message = ' } /** + * @psalm-assert array|null $values + * * @param string|callable():string $message * - * @return mixed + * @return array|null * * @throws InvalidArgumentException */ - public static function nullOrUniqueValues(mixed $values, callable|string $message = ''): mixed + public static function nullOrUniqueValues(mixed $values, callable|string $message = ''): array|null { null === $values || static::uniqueValues($values, $message); @@ -2324,13 +2325,15 @@ public static function nullOrUniqueValues(mixed $values, callable|string $messag } /** + * @psalm-assert iterable $values + * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allUniqueValues(mixed $values, callable|string $message = ''): mixed + public static function allUniqueValues(mixed $values, callable|string $message = ''): iterable { static::isIterable($values); @@ -2342,13 +2345,15 @@ public static function allUniqueValues(mixed $values, callable|string $message = } /** + * @psalm-assert iterable $values + * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrUniqueValues(mixed $values, callable|string $message = ''): mixed + public static function allNullOrUniqueValues(mixed $values, callable|string $message = ''): iterable { static::isIterable($values); @@ -2376,7 +2381,7 @@ public static function nullOrEq(mixed $value, mixed $expect, callable|string $me /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2394,7 +2399,7 @@ public static function allEq(mixed $value, mixed $expect, callable|string $messa /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2426,7 +2431,7 @@ public static function nullOrNotEq(mixed $value, mixed $expect, callable|string /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2444,7 +2449,7 @@ public static function allNotEq(mixed $value, mixed $expect, callable|string $me /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2480,7 +2485,7 @@ public static function nullOrSame(mixed $value, mixed $expect, callable|string $ * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2500,7 +2505,7 @@ public static function allSame(mixed $value, mixed $expect, callable|string $mes * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2536,7 +2541,7 @@ public static function nullOrNotSame(mixed $value, mixed $expect, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2556,7 +2561,7 @@ public static function allNotSame(mixed $value, mixed $expect, callable|string $ * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2592,7 +2597,7 @@ public static function nullOrGreaterThan(mixed $value, mixed $limit, callable|st * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2612,7 +2617,7 @@ public static function allGreaterThan(mixed $value, mixed $limit, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2648,7 +2653,7 @@ public static function nullOrGreaterThanEq(mixed $value, mixed $limit, callable| * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2668,7 +2673,7 @@ public static function allGreaterThanEq(mixed $value, mixed $limit, callable|str * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2704,7 +2709,7 @@ public static function nullOrLessThan(mixed $value, mixed $limit, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2724,7 +2729,7 @@ public static function allLessThan(mixed $value, mixed $limit, callable|string $ * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2760,7 +2765,7 @@ public static function nullOrLessThanEq(mixed $value, mixed $limit, callable|str * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2780,7 +2785,7 @@ public static function allLessThanEq(mixed $value, mixed $limit, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2816,7 +2821,7 @@ public static function nullOrRange(mixed $value, mixed $min, mixed $max, callabl * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2836,7 +2841,7 @@ public static function allRange(mixed $value, mixed $min, mixed $max, callable|s * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2872,7 +2877,7 @@ public static function nullOrOneOf(mixed $value, mixed $values, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2892,7 +2897,7 @@ public static function allOneOf(mixed $value, mixed $values, callable|string $me * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2928,7 +2933,7 @@ public static function nullOrInArray(mixed $value, mixed $values, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2948,7 +2953,7 @@ public static function allInArray(mixed $value, mixed $values, callable|string $ * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -2984,7 +2989,7 @@ public static function nullOrNotOneOf(mixed $value, mixed $values, callable|stri * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3004,7 +3009,7 @@ public static function allNotOneOf(mixed $value, mixed $values, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3040,7 +3045,7 @@ public static function nullOrNotInArray(mixed $value, mixed $values, callable|st * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3060,7 +3065,7 @@ public static function allNotInArray(mixed $value, mixed $values, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3080,11 +3085,11 @@ public static function allNullOrNotInArray(mixed $value, mixed $values, callable * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrContains(mixed $value, mixed $subString, callable|string $message = ''): mixed + public static function nullOrContains(mixed $value, mixed $subString, callable|string $message = ''): string|null { null === $value || static::contains($value, $subString, $message); @@ -3096,7 +3101,7 @@ public static function nullOrContains(mixed $value, mixed $subString, callable|s * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3116,7 +3121,7 @@ public static function allContains(mixed $value, mixed $subString, callable|stri * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3136,11 +3141,11 @@ public static function allNullOrContains(mixed $value, mixed $subString, callabl * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrNotContains(mixed $value, mixed $subString, callable|string $message = ''): mixed + public static function nullOrNotContains(mixed $value, mixed $subString, callable|string $message = ''): string|null { null === $value || static::notContains($value, $subString, $message); @@ -3152,7 +3157,7 @@ public static function nullOrNotContains(mixed $value, mixed $subString, callabl * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3172,7 +3177,7 @@ public static function allNotContains(mixed $value, mixed $subString, callable|s * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3192,11 +3197,11 @@ public static function allNullOrNotContains(mixed $value, mixed $subString, call * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrNotWhitespaceOnly(mixed $value, callable|string $message = ''): mixed + public static function nullOrNotWhitespaceOnly(mixed $value, callable|string $message = ''): string|null { null === $value || static::notWhitespaceOnly($value, $message); @@ -3208,7 +3213,7 @@ public static function nullOrNotWhitespaceOnly(mixed $value, callable|string $me * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3228,7 +3233,7 @@ public static function allNotWhitespaceOnly(mixed $value, callable|string $messa * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3248,11 +3253,11 @@ public static function allNullOrNotWhitespaceOnly(mixed $value, callable|string * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrStartsWith(mixed $value, mixed $prefix, callable|string $message = ''): mixed + public static function nullOrStartsWith(mixed $value, mixed $prefix, callable|string $message = ''): string|null { null === $value || static::startsWith($value, $prefix, $message); @@ -3264,7 +3269,7 @@ public static function nullOrStartsWith(mixed $value, mixed $prefix, callable|st * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3284,7 +3289,7 @@ public static function allStartsWith(mixed $value, mixed $prefix, callable|strin * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3304,11 +3309,11 @@ public static function allNullOrStartsWith(mixed $value, mixed $prefix, callable * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrNotStartsWith(mixed $value, mixed $prefix, callable|string $message = ''): mixed + public static function nullOrNotStartsWith(mixed $value, mixed $prefix, callable|string $message = ''): string|null { null === $value || static::notStartsWith($value, $prefix, $message); @@ -3320,7 +3325,7 @@ public static function nullOrNotStartsWith(mixed $value, mixed $prefix, callable * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3340,7 +3345,7 @@ public static function allNotStartsWith(mixed $value, mixed $prefix, callable|st * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3360,11 +3365,11 @@ public static function allNullOrNotStartsWith(mixed $value, mixed $prefix, calla * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrStartsWithLetter(mixed $value, callable|string $message = ''): mixed + public static function nullOrStartsWithLetter(mixed $value, callable|string $message = ''): string|null { null === $value || static::startsWithLetter($value, $message); @@ -3376,7 +3381,7 @@ public static function nullOrStartsWithLetter(mixed $value, callable|string $mes * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3396,7 +3401,7 @@ public static function allStartsWithLetter(mixed $value, callable|string $messag * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3416,11 +3421,11 @@ public static function allNullOrStartsWithLetter(mixed $value, callable|string $ * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrEndsWith(mixed $value, mixed $suffix, callable|string $message = ''): mixed + public static function nullOrEndsWith(mixed $value, mixed $suffix, callable|string $message = ''): string|null { null === $value || static::endsWith($value, $suffix, $message); @@ -3432,7 +3437,7 @@ public static function nullOrEndsWith(mixed $value, mixed $suffix, callable|stri * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3452,7 +3457,7 @@ public static function allEndsWith(mixed $value, mixed $suffix, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3472,11 +3477,11 @@ public static function allNullOrEndsWith(mixed $value, mixed $suffix, callable|s * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrNotEndsWith(mixed $value, mixed $suffix, callable|string $message = ''): mixed + public static function nullOrNotEndsWith(mixed $value, mixed $suffix, callable|string $message = ''): string|null { null === $value || static::notEndsWith($value, $suffix, $message); @@ -3488,7 +3493,7 @@ public static function nullOrNotEndsWith(mixed $value, mixed $suffix, callable|s * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3508,7 +3513,7 @@ public static function allNotEndsWith(mixed $value, mixed $suffix, callable|stri * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3528,11 +3533,11 @@ public static function allNullOrNotEndsWith(mixed $value, mixed $suffix, callabl * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrRegex(mixed $value, mixed $pattern, callable|string $message = ''): mixed + public static function nullOrRegex(mixed $value, mixed $pattern, callable|string $message = ''): string|null { null === $value || static::regex($value, $pattern, $message); @@ -3544,7 +3549,7 @@ public static function nullOrRegex(mixed $value, mixed $pattern, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3564,7 +3569,7 @@ public static function allRegex(mixed $value, mixed $pattern, callable|string $m * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3584,11 +3589,11 @@ public static function allNullOrRegex(mixed $value, mixed $pattern, callable|str * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrNotRegex(mixed $value, mixed $pattern, callable|string $message = ''): mixed + public static function nullOrNotRegex(mixed $value, mixed $pattern, callable|string $message = ''): string|null { null === $value || static::notRegex($value, $pattern, $message); @@ -3600,7 +3605,7 @@ public static function nullOrNotRegex(mixed $value, mixed $pattern, callable|str * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3620,7 +3625,7 @@ public static function allNotRegex(mixed $value, mixed $pattern, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3640,11 +3645,11 @@ public static function allNullOrNotRegex(mixed $value, mixed $pattern, callable| * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrUnicodeLetters(mixed $value, callable|string $message = ''): mixed + public static function nullOrUnicodeLetters(mixed $value, callable|string $message = ''): string|null { null === $value || static::unicodeLetters($value, $message); @@ -3656,7 +3661,7 @@ public static function nullOrUnicodeLetters(mixed $value, callable|string $messa * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3676,7 +3681,7 @@ public static function allUnicodeLetters(mixed $value, callable|string $message * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3696,11 +3701,11 @@ public static function allNullOrUnicodeLetters(mixed $value, callable|string $me * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrAlpha(mixed $value, callable|string $message = ''): mixed + public static function nullOrAlpha(mixed $value, callable|string $message = ''): string|null { null === $value || static::alpha($value, $message); @@ -3712,7 +3717,7 @@ public static function nullOrAlpha(mixed $value, callable|string $message = ''): * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3732,7 +3737,7 @@ public static function allAlpha(mixed $value, callable|string $message = ''): it * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3752,11 +3757,11 @@ public static function allNullOrAlpha(mixed $value, callable|string $message = ' * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrDigits(mixed $value, callable|string $message = ''): mixed + public static function nullOrDigits(mixed $value, callable|string $message = ''): string|null { null === $value || static::digits($value, $message); @@ -3768,7 +3773,7 @@ public static function nullOrDigits(mixed $value, callable|string $message = '') * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3788,7 +3793,7 @@ public static function allDigits(mixed $value, callable|string $message = ''): i * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3808,11 +3813,11 @@ public static function allNullOrDigits(mixed $value, callable|string $message = * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrAlnum(mixed $value, callable|string $message = ''): mixed + public static function nullOrAlnum(mixed $value, callable|string $message = ''): string|null { null === $value || static::alnum($value, $message); @@ -3824,7 +3829,7 @@ public static function nullOrAlnum(mixed $value, callable|string $message = ''): * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3844,7 +3849,7 @@ public static function allAlnum(mixed $value, callable|string $message = ''): it * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3870,7 +3875,7 @@ public static function allNullOrAlnum(mixed $value, callable|string $message = ' * * @throws InvalidArgumentException */ - public static function nullOrLower(mixed $value, callable|string $message = ''): mixed + public static function nullOrLower(mixed $value, callable|string $message = ''): string|null { null === $value || static::lower($value, $message); @@ -3926,11 +3931,11 @@ public static function allNullOrLower(mixed $value, callable|string $message = ' * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrUpper(mixed $value, callable|string $message = ''): mixed + public static function nullOrUpper(mixed $value, callable|string $message = ''): string|null { null === $value || static::upper($value, $message); @@ -3942,7 +3947,7 @@ public static function nullOrUpper(mixed $value, callable|string $message = ''): * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -3960,11 +3965,11 @@ public static function allUpper(mixed $value, callable|string $message = ''): it /** * @psalm-pure * - * @psalm-assert iterable $value + * @psalm-assert iterable $value * * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ @@ -3984,11 +3989,11 @@ public static function allNullOrUpper(mixed $value, callable|string $message = ' * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrLength(mixed $value, mixed $length, callable|string $message = ''): mixed + public static function nullOrLength(mixed $value, mixed $length, callable|string $message = ''): string|null { null === $value || static::length($value, $length, $message); @@ -4000,7 +4005,7 @@ public static function nullOrLength(mixed $value, mixed $length, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4020,7 +4025,7 @@ public static function allLength(mixed $value, mixed $length, callable|string $m * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4040,11 +4045,11 @@ public static function allNullOrLength(mixed $value, mixed $length, callable|str * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrMinLength(mixed $value, mixed $min, callable|string $message = ''): mixed + public static function nullOrMinLength(mixed $value, mixed $min, callable|string $message = ''): string|null { null === $value || static::minLength($value, $min, $message); @@ -4056,7 +4061,7 @@ public static function nullOrMinLength(mixed $value, mixed $min, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4076,7 +4081,7 @@ public static function allMinLength(mixed $value, mixed $min, callable|string $m * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4096,11 +4101,11 @@ public static function allNullOrMinLength(mixed $value, mixed $min, callable|str * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrMaxLength(mixed $value, mixed $max, callable|string $message = ''): mixed + public static function nullOrMaxLength(mixed $value, mixed $max, callable|string $message = ''): string|null { null === $value || static::maxLength($value, $max, $message); @@ -4112,7 +4117,7 @@ public static function nullOrMaxLength(mixed $value, mixed $max, callable|string * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4132,7 +4137,7 @@ public static function allMaxLength(mixed $value, mixed $max, callable|string $m * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4152,11 +4157,11 @@ public static function allNullOrMaxLength(mixed $value, mixed $max, callable|str * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrLengthBetween(mixed $value, mixed $min, mixed $max, callable|string $message = ''): mixed + public static function nullOrLengthBetween(mixed $value, mixed $min, mixed $max, callable|string $message = ''): string|null { null === $value || static::lengthBetween($value, $min, $max, $message); @@ -4168,7 +4173,7 @@ public static function nullOrLengthBetween(mixed $value, mixed $min, mixed $max, * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4188,7 +4193,7 @@ public static function allLengthBetween(mixed $value, mixed $min, mixed $max, ca * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4206,11 +4211,11 @@ public static function allNullOrLengthBetween(mixed $value, mixed $min, mixed $m /** * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrFileExists(mixed $value, callable|string $message = ''): mixed + public static function nullOrFileExists(mixed $value, callable|string $message = ''): string|null { null === $value || static::fileExists($value, $message); @@ -4220,7 +4225,7 @@ public static function nullOrFileExists(mixed $value, callable|string $message = /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4238,7 +4243,7 @@ public static function allFileExists(mixed $value, callable|string $message = '' /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4256,11 +4261,11 @@ public static function allNullOrFileExists(mixed $value, callable|string $messag /** * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrFile(mixed $value, callable|string $message = ''): mixed + public static function nullOrFile(mixed $value, callable|string $message = ''): string|null { null === $value || static::file($value, $message); @@ -4270,7 +4275,7 @@ public static function nullOrFile(mixed $value, callable|string $message = ''): /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4288,7 +4293,7 @@ public static function allFile(mixed $value, callable|string $message = ''): ite /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4306,11 +4311,11 @@ public static function allNullOrFile(mixed $value, callable|string $message = '' /** * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrDirectory(mixed $value, callable|string $message = ''): mixed + public static function nullOrDirectory(mixed $value, callable|string $message = ''): string|null { null === $value || static::directory($value, $message); @@ -4320,7 +4325,7 @@ public static function nullOrDirectory(mixed $value, callable|string $message = /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4338,7 +4343,7 @@ public static function allDirectory(mixed $value, callable|string $message = '') /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4356,11 +4361,11 @@ public static function allNullOrDirectory(mixed $value, callable|string $message /** * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrReadable(mixed $value, callable|string $message = ''): mixed + public static function nullOrReadable(mixed $value, callable|string $message = ''): string|null { null === $value || static::readable($value, $message); @@ -4370,7 +4375,7 @@ public static function nullOrReadable(mixed $value, callable|string $message = ' /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4388,7 +4393,7 @@ public static function allReadable(mixed $value, callable|string $message = ''): /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4406,11 +4411,11 @@ public static function allNullOrReadable(mixed $value, callable|string $message /** * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrWritable(mixed $value, callable|string $message = ''): mixed + public static function nullOrWritable(mixed $value, callable|string $message = ''): string|null { null === $value || static::writable($value, $message); @@ -4420,7 +4425,7 @@ public static function nullOrWritable(mixed $value, callable|string $message = ' /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4438,7 +4443,7 @@ public static function allWritable(mixed $value, callable|string $message = ''): /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -4462,7 +4467,7 @@ public static function allNullOrWritable(mixed $value, callable|string $message * * @throws InvalidArgumentException */ - public static function nullOrClassExists(mixed $value, callable|string $message = ''): mixed + public static function nullOrClassExists(mixed $value, callable|string $message = ''): string|null { null === $value || static::classExists($value, $message); @@ -4522,7 +4527,7 @@ public static function allNullOrClassExists(mixed $value, callable|string $messa * * @throws InvalidArgumentException */ - public static function nullOrSubclassOf(mixed $value, mixed $class, callable|string $message = ''): mixed + public static function nullOrSubclassOf(mixed $value, mixed $class, callable|string $message = ''): string|null { null === $value || static::subclassOf($value, $class, $message); @@ -4586,7 +4591,7 @@ public static function allNullOrSubclassOf(mixed $value, mixed $class, callable| * * @throws InvalidArgumentException */ - public static function nullOrInterfaceExists(mixed $value, callable|string $message = ''): mixed + public static function nullOrInterfaceExists(mixed $value, callable|string $message = ''): string|null { null === $value || static::interfaceExists($value, $message); @@ -4639,15 +4644,14 @@ public static function allNullOrInterfaceExists(mixed $value, callable|string $m * @template ExpectedType of object * @psalm-assert class-string|ExpectedType|null $value * - * @param class-string|ExpectedType|null $value - * @param class-string $interface - * @param string|callable():string $message + * @param class-string $interface + * @param string|callable():string $message * * @return class-string|ExpectedType|null * * @throws InvalidArgumentException */ - public static function nullOrImplementsInterface(mixed $value, mixed $interface, callable|string $message = ''): mixed + public static function nullOrImplementsInterface(mixed $value, mixed $interface, callable|string $message = ''): object|string|null { null === $value || static::implementsInterface($value, $interface, $message); @@ -4660,9 +4664,8 @@ public static function nullOrImplementsInterface(mixed $value, mixed $interface, * @template ExpectedType of object * @psalm-assert iterable|ExpectedType> $value * - * @param iterable|ExpectedType> $value - * @param class-string $interface - * @param string|callable():string $message + * @param class-string $interface + * @param string|callable():string $message * * @return iterable|ExpectedType> * @@ -4685,9 +4688,8 @@ public static function allImplementsInterface(mixed $value, mixed $interface, ca * @template ExpectedType of object * @psalm-assert iterable|ExpectedType|null> $value * - * @param iterable|ExpectedType|null> $value - * @param class-string $interface - * @param string|callable():string $message + * @param class-string $interface + * @param string|callable():string $message * * @return iterable|ExpectedType|null> * @@ -4710,11 +4712,11 @@ public static function allNullOrImplementsInterface(mixed $value, mixed $interfa * @param string|object|null $classOrObject * @param string|callable():string $message * - * @return mixed + * @return string|object|null * * @throws InvalidArgumentException */ - public static function nullOrPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): mixed + public static function nullOrPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): object|string|null { null === $classOrObject || static::propertyExists($classOrObject, $property, $message); @@ -4727,11 +4729,11 @@ public static function nullOrPropertyExists(mixed $classOrObject, mixed $propert * @param iterable $classOrObject * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): mixed + public static function allPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4748,11 +4750,11 @@ public static function allPropertyExists(mixed $classOrObject, mixed $property, * @param iterable $classOrObject * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): mixed + public static function allNullOrPropertyExists(mixed $classOrObject, mixed $property, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4766,12 +4768,10 @@ public static function allNullOrPropertyExists(mixed $classOrObject, mixed $prop /** * @psalm-pure * - * @param string|object|null $classOrObject + * @param class-string|object|null $classOrObject * @param string|callable():string $message * - * @psalm-param class-string|object|null $classOrObject - * - * @return mixed + * @return class-string|object|null * * @throws InvalidArgumentException */ @@ -4785,16 +4785,14 @@ public static function nullOrPropertyNotExists(mixed $classOrObject, mixed $prop /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message - * - * @psalm-param iterable $classOrObject + * @param iterable $classOrObject + * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allPropertyNotExists(mixed $classOrObject, mixed $property, callable|string $message = ''): mixed + public static function allPropertyNotExists(mixed $classOrObject, mixed $property, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4808,16 +4806,14 @@ public static function allPropertyNotExists(mixed $classOrObject, mixed $propert /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message - * - * @psalm-param iterable $classOrObject + * @param iterable $classOrObject + * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrPropertyNotExists(mixed $classOrObject, mixed $property, callable|string $message = ''): mixed + public static function allNullOrPropertyNotExists(mixed $classOrObject, mixed $property, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4831,16 +4827,14 @@ public static function allNullOrPropertyNotExists(mixed $classOrObject, mixed $p /** * @psalm-pure * - * @param string|object|null $classOrObject + * @param class-string|object|null $classOrObject * @param string|callable():string $message * - * @psalm-param class-string|object|null $classOrObject - * - * @return mixed + * @return class-string|object|null * * @throws InvalidArgumentException */ - public static function nullOrMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): mixed + public static function nullOrMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): object|string|null { null === $classOrObject || static::methodExists($classOrObject, $method, $message); @@ -4850,16 +4844,14 @@ public static function nullOrMethodExists(mixed $classOrObject, mixed $method, c /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message - * - * @psalm-param iterable $classOrObject + * @param iterable $classOrObject + * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): mixed + public static function allMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4873,16 +4865,14 @@ public static function allMethodExists(mixed $classOrObject, mixed $method, call /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message + * @param iterable $classOrObject + * @param string|callable():string $message * - * @psalm-param iterable $classOrObject - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): mixed + public static function allNullOrMethodExists(mixed $classOrObject, mixed $method, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4896,12 +4886,10 @@ public static function allNullOrMethodExists(mixed $classOrObject, mixed $method /** * @psalm-pure * - * @param string|object|null $classOrObject + * @param class-string|object|null $classOrObject * @param string|callable():string $message * - * @psalm-param class-string|object|null $classOrObject - * - * @return mixed + * @return class-string|object|null * * @throws InvalidArgumentException */ @@ -4915,16 +4903,14 @@ public static function nullOrMethodNotExists(mixed $classOrObject, mixed $method /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message - * - * @psalm-param iterable $classOrObject + * @param iterable $classOrObject + * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allMethodNotExists(mixed $classOrObject, mixed $method, callable|string $message = ''): mixed + public static function allMethodNotExists(mixed $classOrObject, mixed $method, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4938,16 +4924,14 @@ public static function allMethodNotExists(mixed $classOrObject, mixed $method, c /** * @psalm-pure * - * @param iterable $classOrObject - * @param string|callable():string $message - * - * @psalm-param iterable $classOrObject + * @param iterable $classOrObject + * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrMethodNotExists(mixed $classOrObject, mixed $method, callable|string $message = ''): mixed + public static function allNullOrMethodNotExists(mixed $classOrObject, mixed $method, callable|string $message = ''): iterable { static::isIterable($classOrObject); @@ -4964,11 +4948,11 @@ public static function allNullOrMethodNotExists(mixed $classOrObject, mixed $met * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return array|null * * @throws InvalidArgumentException */ - public static function nullOrKeyExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function nullOrKeyExists(mixed $array, string|int $key, callable|string $message = ''): array|null { null === $array || static::keyExists($array, $key, $message); @@ -4981,11 +4965,11 @@ public static function nullOrKeyExists(mixed $array, string|int $key, callable|s * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allKeyExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function allKeyExists(mixed $array, string|int $key, callable|string $message = ''): iterable { static::isIterable($array); @@ -5002,11 +4986,11 @@ public static function allKeyExists(mixed $array, string|int $key, callable|stri * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrKeyExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function allNullOrKeyExists(mixed $array, string|int $key, callable|string $message = ''): iterable { static::isIterable($array); @@ -5023,11 +5007,11 @@ public static function allNullOrKeyExists(mixed $array, string|int $key, callabl * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return array|null * * @throws InvalidArgumentException */ - public static function nullOrKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function nullOrKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): array|null { null === $array || static::keyNotExists($array, $key, $message); @@ -5040,11 +5024,11 @@ public static function nullOrKeyNotExists(mixed $array, string|int $key, callabl * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function allKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): iterable { static::isIterable($array); @@ -5061,11 +5045,11 @@ public static function allKeyNotExists(mixed $array, string|int $key, callable|s * @param string|int $key * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): mixed + public static function allNullOrKeyNotExists(mixed $array, string|int $key, callable|string $message = ''): iterable { static::isIterable($array); @@ -5087,7 +5071,7 @@ public static function allNullOrKeyNotExists(mixed $array, string|int $key, call * * @throws InvalidArgumentException */ - public static function nullOrValidArrayKey(mixed $value, callable|string $message = ''): mixed + public static function nullOrValidArrayKey(mixed $value, callable|string $message = ''): string|int|null { null === $value || static::validArrayKey($value, $message); @@ -5141,11 +5125,11 @@ public static function allNullOrValidArrayKey(mixed $value, callable|string $mes /** * @param string|callable():string $message * - * @return mixed + * @return Countable|array|null * * @throws InvalidArgumentException */ - public static function nullOrCount(mixed $array, mixed $number, callable|string $message = ''): mixed + public static function nullOrCount(mixed $array, mixed $number, callable|string $message = ''): Countable|array|null { null === $array || static::count($array, $number, $message); @@ -5155,11 +5139,11 @@ public static function nullOrCount(mixed $array, mixed $number, callable|string /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allCount(mixed $array, mixed $number, callable|string $message = ''): mixed + public static function allCount(mixed $array, mixed $number, callable|string $message = ''): iterable { static::isIterable($array); @@ -5173,11 +5157,11 @@ public static function allCount(mixed $array, mixed $number, callable|string $me /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrCount(mixed $array, mixed $number, callable|string $message = ''): mixed + public static function allNullOrCount(mixed $array, mixed $number, callable|string $message = ''): iterable { static::isIterable($array); @@ -5191,11 +5175,11 @@ public static function allNullOrCount(mixed $array, mixed $number, callable|stri /** * @param string|callable():string $message * - * @return mixed + * @return Countable|array|null * * @throws InvalidArgumentException */ - public static function nullOrMinCount(mixed $array, mixed $min, callable|string $message = ''): mixed + public static function nullOrMinCount(mixed $array, mixed $min, callable|string $message = ''): Countable|array|null { null === $array || static::minCount($array, $min, $message); @@ -5205,11 +5189,11 @@ public static function nullOrMinCount(mixed $array, mixed $min, callable|string /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allMinCount(mixed $array, mixed $min, callable|string $message = ''): mixed + public static function allMinCount(mixed $array, mixed $min, callable|string $message = ''): iterable { static::isIterable($array); @@ -5223,11 +5207,11 @@ public static function allMinCount(mixed $array, mixed $min, callable|string $me /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrMinCount(mixed $array, mixed $min, callable|string $message = ''): mixed + public static function allNullOrMinCount(mixed $array, mixed $min, callable|string $message = ''): iterable { static::isIterable($array); @@ -5241,11 +5225,11 @@ public static function allNullOrMinCount(mixed $array, mixed $min, callable|stri /** * @param string|callable():string $message * - * @return mixed + * @return Countable|array|null * * @throws InvalidArgumentException */ - public static function nullOrMaxCount(mixed $array, mixed $max, callable|string $message = ''): mixed + public static function nullOrMaxCount(mixed $array, mixed $max, callable|string $message = ''): Countable|array|null { null === $array || static::maxCount($array, $max, $message); @@ -5255,11 +5239,11 @@ public static function nullOrMaxCount(mixed $array, mixed $max, callable|string /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allMaxCount(mixed $array, mixed $max, callable|string $message = ''): mixed + public static function allMaxCount(mixed $array, mixed $max, callable|string $message = ''): iterable { static::isIterable($array); @@ -5273,11 +5257,11 @@ public static function allMaxCount(mixed $array, mixed $max, callable|string $me /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrMaxCount(mixed $array, mixed $max, callable|string $message = ''): mixed + public static function allNullOrMaxCount(mixed $array, mixed $max, callable|string $message = ''): iterable { static::isIterable($array); @@ -5291,11 +5275,11 @@ public static function allNullOrMaxCount(mixed $array, mixed $max, callable|stri /** * @param string|callable():string $message * - * @return mixed + * @return Countable|array|null * * @throws InvalidArgumentException */ - public static function nullOrCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): mixed + public static function nullOrCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): Countable|array|null { null === $array || static::countBetween($array, $min, $max, $message); @@ -5305,11 +5289,11 @@ public static function nullOrCountBetween(mixed $array, mixed $min, mixed $max, /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): mixed + public static function allCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): iterable { static::isIterable($array); @@ -5323,11 +5307,11 @@ public static function allCountBetween(mixed $array, mixed $min, mixed $max, cal /** * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): mixed + public static function allNullOrCountBetween(mixed $array, mixed $min, mixed $max, callable|string $message = ''): iterable { static::isIterable($array); @@ -5349,7 +5333,7 @@ public static function allNullOrCountBetween(mixed $array, mixed $min, mixed $ma * * @throws InvalidArgumentException */ - public static function nullOrIsList(mixed $array, callable|string $message = ''): mixed + public static function nullOrIsList(mixed $array, callable|string $message = ''): array|null { null === $array || static::isList($array, $message); @@ -5367,7 +5351,7 @@ public static function nullOrIsList(mixed $array, callable|string $message = '') * * @throws InvalidArgumentException */ - public static function allIsList(mixed $array, callable|string $message = ''): mixed + public static function allIsList(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5389,7 +5373,7 @@ public static function allIsList(mixed $array, callable|string $message = ''): m * * @throws InvalidArgumentException */ - public static function allNullOrIsList(mixed $array, callable|string $message = ''): mixed + public static function allNullOrIsList(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5411,7 +5395,7 @@ public static function allNullOrIsList(mixed $array, callable|string $message = * * @throws InvalidArgumentException */ - public static function nullOrIsNonEmptyList(mixed $array, callable|string $message = ''): mixed + public static function nullOrIsNonEmptyList(mixed $array, callable|string $message = ''): array|null { null === $array || static::isNonEmptyList($array, $message); @@ -5429,7 +5413,7 @@ public static function nullOrIsNonEmptyList(mixed $array, callable|string $messa * * @throws InvalidArgumentException */ - public static function allIsNonEmptyList(mixed $array, callable|string $message = ''): mixed + public static function allIsNonEmptyList(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5451,7 +5435,7 @@ public static function allIsNonEmptyList(mixed $array, callable|string $message * * @throws InvalidArgumentException */ - public static function allNullOrIsNonEmptyList(mixed $array, callable|string $message = ''): mixed + public static function allNullOrIsNonEmptyList(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5475,7 +5459,7 @@ public static function allNullOrIsNonEmptyList(mixed $array, callable|string $me * * @throws InvalidArgumentException */ - public static function nullOrIsMap(mixed $array, callable|string $message = ''): mixed + public static function nullOrIsMap(mixed $array, callable|string $message = ''): array|null { null === $array || static::isMap($array, $message); @@ -5495,7 +5479,7 @@ public static function nullOrIsMap(mixed $array, callable|string $message = ''): * * @throws InvalidArgumentException */ - public static function allIsMap(mixed $array, callable|string $message = ''): mixed + public static function allIsMap(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5519,7 +5503,7 @@ public static function allIsMap(mixed $array, callable|string $message = ''): mi * * @throws InvalidArgumentException */ - public static function allNullOrIsMap(mixed $array, callable|string $message = ''): mixed + public static function allNullOrIsMap(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5531,16 +5515,14 @@ public static function allNullOrIsMap(mixed $array, callable|string $message = ' } /** - * @psalm-assert callable|null $callable - * - * @param Closure|callable|null $callable + * @param callable|null $callable * @param string|callable():string $message * - * @return callable|null + * @return Closure|callable-string|null * * @throws InvalidArgumentException */ - public static function nullOrIsStatic(mixed $callable, callable|string $message = ''): mixed + public static function nullOrIsStatic(mixed $callable, callable|string $message = ''): Closure|string|null { null === $callable || static::isStatic($callable, $message); @@ -5548,16 +5530,14 @@ public static function nullOrIsStatic(mixed $callable, callable|string $message } /** - * @psalm-assert iterable $callable - * - * @param iterable $callable - * @param string|callable():string $message + * @param iterable $callable + * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ - public static function allIsStatic(mixed $callable, callable|string $message = ''): mixed + public static function allIsStatic(mixed $callable, callable|string $message = ''): iterable { static::isIterable($callable); @@ -5569,16 +5549,14 @@ public static function allIsStatic(mixed $callable, callable|string $message = ' } /** - * @psalm-assert iterable $callable - * - * @param iterable $callable - * @param string|callable():string $message + * @param iterable $callable + * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrIsStatic(mixed $callable, callable|string $message = ''): mixed + public static function allNullOrIsStatic(mixed $callable, callable|string $message = ''): iterable { static::isIterable($callable); @@ -5590,16 +5568,14 @@ public static function allNullOrIsStatic(mixed $callable, callable|string $messa } /** - * @psalm-assert callable|null $callable - * - * @param Closure|callable|null $callable + * @param callable|null $callable * @param string|callable():string $message * - * @return callable|null + * @return Closure|callable-string|null * * @throws InvalidArgumentException */ - public static function nullOrNotStatic(mixed $callable, callable|string $message = ''): mixed + public static function nullOrNotStatic(mixed $callable, callable|string $message = ''): Closure|string|null { null === $callable || static::notStatic($callable, $message); @@ -5607,16 +5583,14 @@ public static function nullOrNotStatic(mixed $callable, callable|string $message } /** - * @psalm-assert iterable $callable - * - * @param iterable $callable - * @param string|callable():string $message + * @param iterable $callable + * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ - public static function allNotStatic(mixed $callable, callable|string $message = ''): mixed + public static function allNotStatic(mixed $callable, callable|string $message = ''): iterable { static::isIterable($callable); @@ -5628,16 +5602,14 @@ public static function allNotStatic(mixed $callable, callable|string $message = } /** - * @psalm-assert iterable $callable - * - * @param iterable $callable - * @param string|callable():string $message + * @param iterable $callable + * @param string|callable():string $message * - * @return iterable + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrNotStatic(mixed $callable, callable|string $message = ''): mixed + public static function allNullOrNotStatic(mixed $callable, callable|string $message = ''): iterable { static::isIterable($callable); @@ -5656,11 +5628,11 @@ public static function allNullOrNotStatic(mixed $callable, callable|string $mess * @param array|null $array * @param string|callable():string $message * - * @return mixed + * @return non-empty-array|null * * @throws InvalidArgumentException */ - public static function nullOrIsNonEmptyMap(mixed $array, callable|string $message = ''): mixed + public static function nullOrIsNonEmptyMap(mixed $array, callable|string $message = ''): array|null { null === $array || static::isNonEmptyMap($array, $message); @@ -5675,11 +5647,11 @@ public static function nullOrIsNonEmptyMap(mixed $array, callable|string $messag * @param iterable> $array * @param string|callable():string $message * - * @return mixed + * @return iterable> * * @throws InvalidArgumentException */ - public static function allIsNonEmptyMap(mixed $array, callable|string $message = ''): mixed + public static function allIsNonEmptyMap(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5700,11 +5672,11 @@ public static function allIsNonEmptyMap(mixed $array, callable|string $message = * @param iterable|null> $array * @param string|callable():string $message * - * @return iterable + * @return iterable|null> * * @throws InvalidArgumentException */ - public static function allNullOrIsNonEmptyMap(mixed $array, callable|string $message = ''): mixed + public static function allNullOrIsNonEmptyMap(mixed $array, callable|string $message = ''): iterable { static::isIterable($array); @@ -5720,11 +5692,11 @@ public static function allNullOrIsNonEmptyMap(mixed $array, callable|string $mes * * @param string|callable():string $message * - * @return mixed + * @return string|null * * @throws InvalidArgumentException */ - public static function nullOrUuid(mixed $value, callable|string $message = ''): mixed + public static function nullOrUuid(mixed $value, callable|string $message = ''): string|null { null === $value || static::uuid($value, $message); @@ -5736,7 +5708,7 @@ public static function nullOrUuid(mixed $value, callable|string $message = ''): * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -5756,7 +5728,7 @@ public static function allUuid(mixed $value, callable|string $message = ''): ite * * @param string|callable():string $message * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ @@ -5772,15 +5744,14 @@ public static function allNullOrUuid(mixed $value, callable|string $message = '' } /** + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * - * @return mixed + * @return callable|null * * @throws InvalidArgumentException */ - public static function nullOrThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): mixed + public static function nullOrThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): callable|null { null === $expression || static::throws($expression, $class, $message); @@ -5788,15 +5759,14 @@ public static function nullOrThrows(mixed $expression, string $class = 'Throwabl } /** + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): mixed + public static function allThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): iterable { static::isIterable($expression); @@ -5808,15 +5778,14 @@ public static function allThrows(mixed $expression, string $class = 'Throwable', } /** + * @param class-string $class * @param string|callable():string $message * - * @psalm-param class-string $class - * - * @return mixed + * @return iterable * * @throws InvalidArgumentException */ - public static function allNullOrThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): mixed + public static function allNullOrThrows(mixed $expression, string $class = 'Throwable', callable|string $message = ''): iterable { static::isIterable($expression); diff --git a/src/PsalmPlugin.php b/src/PsalmPlugin.php new file mode 100644 index 00000000..7f9a8ee6 --- /dev/null +++ b/src/PsalmPlugin.php @@ -0,0 +1,46 @@ +registerHooksFromClass(self::class); + } + + public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $event): void + { + if (!str_starts_with($event->getMethodId(), Assert::class.'::')) { + return; + } + + $firstArg = $event->getExpr()->getArgs()[0] ?? null; + if ($firstArg === null) { + return; + } + + $varId = ExpressionIdentifier::getExtendedVarId( + $firstArg->value, + $event->getContext()->self, + $event->getStatementsSource() + ); + + if ($varId === null || !isset($event->getContext()->vars_in_scope[$varId])) { + return; + } + + $candidateType = $event->getContext()->vars_in_scope[$varId]; + + $event->setReturnTypeCandidate($candidateType); + } +} diff --git a/tests/ProjectCodeTest.php b/tests/ProjectCodeTest.php index 1afb7286..a7b2a2d7 100644 --- a/tests/ProjectCodeTest.php +++ b/tests/ProjectCodeTest.php @@ -11,6 +11,7 @@ use ReflectionClass; use ReflectionMethod; use Webmozart\Assert\Bin\MixinGenerator; +use Webmozart\Assert\Bin\StaticAnalysisNonReturnGenerator; #[CoversNothing] class ProjectCodeTest extends TestCase @@ -149,6 +150,21 @@ public function testHasCorrespondingStaticAnalysisFile(ReflectionMethod $method) ); } + #[DataProvider('provideMethods')] + public function testHasCorrespondingStaticAnalysisReturnTest(ReflectionMethod $method): void + { + $file = __DIR__.'/static-analysis/assert-'.$method->getName().'.php'; + + $this->assertFileExists($file); + + $contents = file_get_contents($file); + $this->assertIsString($contents); + $this->assertMatchesRegularExpression( + '/return Assert::'.preg_quote($method->getName(), '/').'\(/', + $contents + ); + } + public function testMixinIsUpToDateVersion(): void { if (PHP_OS_FAMILY === 'Windows') { @@ -166,6 +182,31 @@ public function testMixinIsUpToDateVersion(): void $this->assertEquals($generator->generate(), $actual, 'please regenerate Mixin with `php bin/generate.php` command in the project root'); } + public function testNonReturnStaticAnalysisTestsAreUpToDate(): void + { + if (PHP_OS_FAMILY === 'Windows') { + $this->markTestSkipped('non-return static analysis generator is not expected to run on Windows'); + + return; + } + + require_once __DIR__.'/../bin/src/StaticAnalysisNonReturnGenerator.php'; + + $generator = new StaticAnalysisNonReturnGenerator(__DIR__.'/static-analysis'); + + foreach ($generator->generatedFiles() as $targetFile => $expectedContent) { + $this->assertFileExists($targetFile); + + $actualContent = file_get_contents($targetFile); + $this->assertIsString($actualContent); + $this->assertEquals( + $expectedContent, + $actualContent, + 'please regenerate static analysis tests with `php bin/generate.php` command in the project root' + ); + } + } + /** * @return array */ diff --git a/tests/static-analysis/assert-alnum.php b/tests/static-analysis/assert-alnum.php index b296eade..39efb287 100644 --- a/tests/static-analysis/assert-alnum.php +++ b/tests/static-analysis/assert-alnum.php @@ -11,9 +11,7 @@ */ function alnum(string $value): string { - Assert::alnum($value); - - return $value; + return Assert::alnum($value); } /** @@ -21,9 +19,7 @@ function alnum(string $value): string */ function nullOrAlnum(?string $value): ?string { - Assert::nullOrAlnum($value); - - return $value; + return Assert::nullOrAlnum($value); } /** @@ -33,9 +29,7 @@ function nullOrAlnum(?string $value): ?string */ function allAlnum(iterable $value): iterable { - Assert::allAlnum($value); - - return $value; + return Assert::allAlnum($value); } /** @@ -45,7 +39,5 @@ function allAlnum(iterable $value): iterable */ function allNullOrAlnum(iterable $value): iterable { - Assert::allNullOrAlnum($value); - - return $value; + return Assert::allNullOrAlnum($value); } diff --git a/tests/static-analysis/assert-alpha.php b/tests/static-analysis/assert-alpha.php index c86f9378..c93d68b9 100644 --- a/tests/static-analysis/assert-alpha.php +++ b/tests/static-analysis/assert-alpha.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function alpha(mixed $value): mixed { - Assert::alpha($value); - - return $value; + return Assert::alpha($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrAlpha(mixed $value): mixed { - Assert::nullOrAlpha($value); - - return $value; + return Assert::nullOrAlpha($value); } /** * @psalm-pure - * - * @param mixed $value */ function allAlpha(mixed $value): mixed { - Assert::allAlpha($value); - - return $value; + return Assert::allAlpha($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrAlpha(mixed $value): mixed { - Assert::allNullOrAlpha($value); - - return $value; + return Assert::allNullOrAlpha($value); } diff --git a/tests/static-analysis/assert-boolean.php b/tests/static-analysis/assert-boolean.php index 99fea5c2..f9d5ff7a 100644 --- a/tests/static-analysis/assert-boolean.php +++ b/tests/static-analysis/assert-boolean.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function boolean(mixed $value): bool { - Assert::boolean($value); - - return $value; + return Assert::boolean($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrBoolean(mixed $value): ?bool { - Assert::nullOrBoolean($value); - - return $value; + return Assert::nullOrBoolean($value); } /** * @psalm-pure - * - * @param mixed $value */ function allBoolean(mixed $value): iterable { - Assert::allBoolean($value); - - return $value; + return Assert::allBoolean($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrBoolean(mixed $value): iterable { - Assert::allNullOrBoolean($value); - - return $value; + return Assert::allNullOrBoolean($value); } diff --git a/tests/static-analysis/assert-classExists.php b/tests/static-analysis/assert-classExists.php index ddadf259..0c6eec7d 100644 --- a/tests/static-analysis/assert-classExists.php +++ b/tests/static-analysis/assert-classExists.php @@ -7,45 +7,37 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * * * @return class-string */ function classExists(mixed $value): string { - Assert::classExists($value); - - return $value; + return Assert::classExists($value); } /** - * @param mixed $value + * * * @return class-string|null */ function nullOrClassExists(mixed $value): ?string { - Assert::nullOrClassExists($value); - - return $value; + return Assert::nullOrClassExists($value); } /** - * @param mixed $value + * */ function allClassExists(mixed $value): iterable { - Assert::allClassExists($value); - - return $value; + return Assert::allClassExists($value); } /** - * @param mixed $value + * */ function allNullOrClassExists(mixed $value): iterable { - Assert::allNullOrClassExists($value); - - return $value; + return Assert::allNullOrClassExists($value); } diff --git a/tests/static-analysis/assert-contains.php b/tests/static-analysis/assert-contains.php index 8b5d7ff8..7209ebb1 100644 --- a/tests/static-analysis/assert-contains.php +++ b/tests/static-analysis/assert-contains.php @@ -11,9 +11,7 @@ */ function contains(string $value, string $subString): string { - Assert::contains($value, $subString); - - return $value; + return Assert::contains($value, $subString); } /** @@ -21,9 +19,7 @@ function contains(string $value, string $subString): string */ function nullOrContains(?string $value, string $subString): ?string { - Assert::nullOrContains($value, $subString); - - return $value; + return Assert::nullOrContains($value, $subString); } /** @@ -33,9 +29,7 @@ function nullOrContains(?string $value, string $subString): ?string */ function allContains(iterable $value, string $subString): iterable { - Assert::allContains($value, $subString); - - return $value; + return Assert::allContains($value, $subString); } /** @@ -45,7 +39,5 @@ function allContains(iterable $value, string $subString): iterable */ function allNullOrContains(iterable $value, string $subString): iterable { - Assert::allNullOrContains($value, $subString); - - return $value; + return Assert::allNullOrContains($value, $subString); } diff --git a/tests/static-analysis/assert-count.php b/tests/static-analysis/assert-count.php index ffa75eeb..ee8f1251 100644 --- a/tests/static-analysis/assert-count.php +++ b/tests/static-analysis/assert-count.php @@ -12,9 +12,7 @@ */ function count(Countable|array $value, int $number): Countable|array { - Assert::count($value, $number); - - return $value; + return Assert::count($value, $number); } /** @@ -22,9 +20,7 @@ function count(Countable|array $value, int $number): Countable|array */ function nullOrCount(Countable|array|null $value, int $number): Countable|array|null { - Assert::nullOrCount($value, $number); - - return $value; + return Assert::nullOrCount($value, $number); } /** @@ -32,9 +28,7 @@ function nullOrCount(Countable|array|null $value, int $number): Countable|array| */ function allCount(iterable $value, int $number): iterable { - Assert::allCount($value, $number); - - return $value; + return Assert::allCount($value, $number); } /** @@ -42,7 +36,5 @@ function allCount(iterable $value, int $number): iterable */ function allNullOrCount(iterable $value, int $number): iterable { - Assert::allCount($value, $number); - - return $value; + return Assert::allCount($value, $number); } diff --git a/tests/static-analysis/assert-countBetween.php b/tests/static-analysis/assert-countBetween.php index eb6b3ded..896b9274 100644 --- a/tests/static-analysis/assert-countBetween.php +++ b/tests/static-analysis/assert-countBetween.php @@ -12,11 +12,9 @@ * @param int|float $min * @param int|float $max */ -function countBetween($value, $min, $max): Countable|array +function countBetween(mixed $value, $min, $max): Countable|array { - Assert::countBetween($value, $min, $max); - - return $value; + return Assert::countBetween($value, $min, $max); } /** @@ -24,11 +22,9 @@ function countBetween($value, $min, $max): Countable|array * @param int|float $min * @param int|float $max */ -function nullOrCountBetween($value, $min, $max): Countable|array|null +function nullOrCountBetween(mixed $value, $min, $max): Countable|array|null { - Assert::nullOrCountBetween($value, $min, $max); - - return $value; + return Assert::nullOrCountBetween($value, $min, $max); } /** @@ -38,9 +34,7 @@ function nullOrCountBetween($value, $min, $max): Countable|array|null */ function allCountBetween(iterable $value, $min, $max): iterable { - Assert::allCountBetween($value, $min, $max); - - return $value; + return Assert::allCountBetween($value, $min, $max); } /** @@ -50,7 +44,5 @@ function allCountBetween(iterable $value, $min, $max): iterable */ function allNullOrCountBetween(iterable $value, $min, $max): iterable { - Assert::allNullOrCountBetween($value, $min, $max); - - return $value; + return Assert::allNullOrCountBetween($value, $min, $max); } diff --git a/tests/static-analysis/assert-digits.php b/tests/static-analysis/assert-digits.php index e201f926..41d51c08 100644 --- a/tests/static-analysis/assert-digits.php +++ b/tests/static-analysis/assert-digits.php @@ -11,9 +11,7 @@ */ function digits(string $value): string { - Assert::digits($value); - - return $value; + return Assert::digits($value); } /** @@ -21,9 +19,7 @@ function digits(string $value): string */ function nullOrDigits(?string $value): ?string { - Assert::nullOrDigits($value); - - return $value; + return Assert::nullOrDigits($value); } /** @@ -33,9 +29,7 @@ function nullOrDigits(?string $value): ?string */ function allDigits(iterable $value): iterable { - Assert::allDigits($value); - - return $value; + return Assert::allDigits($value); } /** @@ -45,7 +39,5 @@ function allDigits(iterable $value): iterable */ function allNullOrDigits(iterable $value): iterable { - Assert::allNullOrDigits($value); - - return $value; + return Assert::allNullOrDigits($value); } diff --git a/tests/static-analysis/assert-directory.php b/tests/static-analysis/assert-directory.php index b3589156..b555fa27 100644 --- a/tests/static-analysis/assert-directory.php +++ b/tests/static-analysis/assert-directory.php @@ -7,41 +7,33 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * */ function directory(mixed $value): mixed { - Assert::directory($value); - - return $value; + return Assert::directory($value); } /** - * @param mixed $value + * */ function nullOrDirectory(mixed $value): mixed { - Assert::nullOrDirectory($value); - - return $value; + return Assert::nullOrDirectory($value); } /** - * @param mixed $value + * */ function allDirectory(mixed $value): mixed { - Assert::allDirectory($value); - - return $value; + return Assert::allDirectory($value); } /** - * @param mixed $value + * */ function allNullOrDirectory(mixed $value): mixed { - Assert::allNullOrDirectory($value); - - return $value; + return Assert::allNullOrDirectory($value); } diff --git a/tests/static-analysis/assert-email.php b/tests/static-analysis/assert-email.php index bc9eae9c..ee794523 100644 --- a/tests/static-analysis/assert-email.php +++ b/tests/static-analysis/assert-email.php @@ -6,42 +6,30 @@ use Webmozart\Assert\Assert; -/** - * @param mixed $value - */ -function email(mixed $value): mixed +function email(string $value): string { - Assert::email($value); - - return $value; + return Assert::email($value); } -/** - * @param mixed $value - */ -function nullOrEmail(mixed $value): mixed +function nullOrEmail(?string $value): ?string { - Assert::nullOrEmail($value); - - return $value; + return Assert::nullOrEmail($value); } /** - * @param mixed $value + * @param iterable $value + * @return iterable */ -function allEmail(mixed $value): mixed +function allEmail(mixed $value): iterable { - Assert::allEmail($value); - - return $value; + return Assert::allEmail($value); } /** - * @param mixed $value + * @param iterable $value + * @return iterable */ -function allNullOrEmail(mixed $value): mixed +function allNullOrEmail(mixed $value): iterable { - Assert::allNullOrEmail($value); - - return $value; + return Assert::allNullOrEmail($value); } diff --git a/tests/static-analysis/assert-endsWith.php b/tests/static-analysis/assert-endsWith.php index 62e51223..90075ca1 100644 --- a/tests/static-analysis/assert-endsWith.php +++ b/tests/static-analysis/assert-endsWith.php @@ -11,9 +11,7 @@ */ function endsWith(string $value, string $suffix): string { - Assert::endsWith($value, $suffix); - - return $value; + return Assert::endsWith($value, $suffix); } /** @@ -21,9 +19,7 @@ function endsWith(string $value, string $suffix): string */ function nullOrEndsWith(?string $value, string $suffix): ?string { - Assert::nullOrEndsWith($value, $suffix); - - return $value; + return Assert::nullOrEndsWith($value, $suffix); } /** @@ -33,9 +29,7 @@ function nullOrEndsWith(?string $value, string $suffix): ?string */ function allEndsWith(iterable $value, string $suffix): iterable { - Assert::allEndsWith($value, $suffix); - - return $value; + return Assert::allEndsWith($value, $suffix); } /** @@ -45,7 +39,5 @@ function allEndsWith(iterable $value, string $suffix): iterable */ function allNullOrEndsWith(iterable $value, string $suffix): iterable { - Assert::allNullOrEndsWith($value, $suffix); - - return $value; + return Assert::allNullOrEndsWith($value, $suffix); } diff --git a/tests/static-analysis/assert-eq.php b/tests/static-analysis/assert-eq.php index a99a965b..7d150fcf 100644 --- a/tests/static-analysis/assert-eq.php +++ b/tests/static-analysis/assert-eq.php @@ -7,45 +7,37 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * * @param mixed $expect */ -function eq($value, $expect): mixed +function eq(mixed $value, mixed $expect): mixed { - Assert::eq($value, $expect); - - return $value; + return Assert::eq($value, $expect); } /** - * @param mixed $value + * * @param mixed $expect */ -function nullOrEq($value, $expect): mixed +function nullOrEq(mixed $value, mixed $expect): mixed { - Assert::nullOrEq($value, $expect); - - return $value; + return Assert::nullOrEq($value, $expect); } /** - * @param mixed $value + * * @param mixed $expect */ -function allEq($value, $expect): mixed +function allEq(mixed $value, mixed $expect): mixed { - Assert::allEq($value, $expect); - - return $value; + return Assert::allEq($value, $expect); } /** - * @param mixed $value + * * @param mixed $expect */ -function allNullOrEq($value, $expect): mixed +function allNullOrEq(mixed $value, mixed $expect): mixed { - Assert::allNullOrEq($value, $expect); - - return $value; + return Assert::allNullOrEq($value, $expect); } diff --git a/tests/static-analysis/assert-false.php b/tests/static-analysis/assert-false.php index 89ac3383..b73004fb 100644 --- a/tests/static-analysis/assert-false.php +++ b/tests/static-analysis/assert-false.php @@ -9,51 +9,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return false */ function false(mixed $value): bool { - Assert::false($value); - - return $value; + return Assert::false($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|false */ function nullOrFalse(mixed $value): ?bool { - Assert::nullOrFalse($value); - - return $value; + return Assert::nullOrFalse($value); } /** * @psalm-pure - * - * @param mixed $value */ function allFalse(mixed $value): iterable { - Assert::allFalse($value); - - return $value; + return Assert::allFalse($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrFalse(mixed $value): iterable { - Assert::allFalse($value); - - return $value; + return Assert::allFalse($value); } diff --git a/tests/static-analysis/assert-file.php b/tests/static-analysis/assert-file.php index a402bc71..f041b57e 100644 --- a/tests/static-analysis/assert-file.php +++ b/tests/static-analysis/assert-file.php @@ -7,41 +7,33 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * */ function file(mixed $value): mixed { - Assert::file($value); - - return $value; + return Assert::file($value); } /** - * @param mixed $value + * */ function nullOrFile(mixed $value): mixed { - Assert::nullOrFile($value); - - return $value; + return Assert::nullOrFile($value); } /** - * @param mixed $value + * */ function allFile(mixed $value): mixed { - Assert::allFile($value); - - return $value; + return Assert::allFile($value); } /** - * @param mixed $value + * */ function allNullOrFile(mixed $value): mixed { - Assert::allNullOrFile($value); - - return $value; + return Assert::allNullOrFile($value); } diff --git a/tests/static-analysis/assert-fileExists.php b/tests/static-analysis/assert-fileExists.php index a83e6940..22a57899 100644 --- a/tests/static-analysis/assert-fileExists.php +++ b/tests/static-analysis/assert-fileExists.php @@ -7,41 +7,33 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * */ function fileExists(mixed $value): mixed { - Assert::fileExists($value); - - return $value; + return Assert::fileExists($value); } /** - * @param mixed $value + * */ function nullOrFileExists(mixed $value): mixed { - Assert::nullOrFileExists($value); - - return $value; + return Assert::nullOrFileExists($value); } /** - * @param mixed $value + * */ function allFileExists(mixed $value): mixed { - Assert::allFileExists($value); - - return $value; + return Assert::allFileExists($value); } /** - * @param mixed $value + * */ function allNullOrFileExists(mixed $value): mixed { - Assert::allNullOrFileExists($value); - - return $value; + return Assert::allNullOrFileExists($value); } diff --git a/tests/static-analysis/assert-float.php b/tests/static-analysis/assert-float.php index 33132100..125dc5bb 100644 --- a/tests/static-analysis/assert-float.php +++ b/tests/static-analysis/assert-float.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function float(mixed $value): float { - Assert::float($value); - - return $value; + return Assert::float($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrFloat(mixed $value): ?float { - Assert::nullOrFloat($value); - - return $value; + return Assert::nullOrFloat($value); } /** * @psalm-pure - * - * @param mixed $value */ function allFloat(mixed $value): iterable { - Assert::allFloat($value); - - return $value; + return Assert::allFloat($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrFloat(mixed $value): iterable { - Assert::allNullOrFloat($value); - - return $value; + return Assert::allNullOrFloat($value); } diff --git a/tests/static-analysis/assert-greaterThan.php b/tests/static-analysis/assert-greaterThan.php index 32925c29..e7287c5c 100644 --- a/tests/static-analysis/assert-greaterThan.php +++ b/tests/static-analysis/assert-greaterThan.php @@ -8,52 +8,36 @@ /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function greaterThan($value, $limit): mixed +function greaterThan(mixed $value, $limit): mixed { - Assert::greaterThan($value, $limit); - - return $value; + return Assert::greaterThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function nullOrGreaterThan($value, $limit): mixed +function nullOrGreaterThan(mixed $value, mixed $limit): mixed { - Assert::nullOrGreaterThan($value, $limit); - - return $value; + return Assert::nullOrGreaterThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allGreaterThan($value, $limit): mixed +function allGreaterThan(mixed $value, mixed $limit): mixed { - Assert::allGreaterThan($value, $limit); - - return $value; + return Assert::allGreaterThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allNullOrGreaterThan($value, $limit): mixed +function allNullOrGreaterThan(mixed $value, mixed $limit): mixed { - Assert::allNullOrGreaterThan($value, $limit); - - return $value; + return Assert::allNullOrGreaterThan($value, $limit); } diff --git a/tests/static-analysis/assert-greaterThanEq.php b/tests/static-analysis/assert-greaterThanEq.php index 18b85b00..492cf014 100644 --- a/tests/static-analysis/assert-greaterThanEq.php +++ b/tests/static-analysis/assert-greaterThanEq.php @@ -8,52 +8,35 @@ /** * @psalm-pure - * - * @param mixed $value - * @param mixed $limit */ -function greaterThanEq($value, $limit): mixed +function greaterThanEq(mixed $value, mixed $limit): mixed { - Assert::greaterThanEq($value, $limit); - - return $value; + return Assert::greaterThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function nullOrGreaterThanEq($value, $limit): mixed +function nullOrGreaterThanEq(mixed $value, mixed $limit): mixed { - Assert::nullOrGreaterThanEq($value, $limit); - - return $value; + return Assert::nullOrGreaterThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allGreaterThanEq($value, $limit): mixed +function allGreaterThanEq(mixed $value, mixed $limit): mixed { - Assert::allGreaterThanEq($value, $limit); - - return $value; + return Assert::allGreaterThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allNullOrGreaterThanEq($value, $limit): mixed +function allNullOrGreaterThanEq(mixed $value, mixed $limit): mixed { - Assert::allNullOrGreaterThanEq($value, $limit); - - return $value; + return Assert::allNullOrGreaterThanEq($value, $limit); } diff --git a/tests/static-analysis/assert-implementsInterface.php b/tests/static-analysis/assert-implementsInterface.php index e61d6e81..03e1c22a 100644 --- a/tests/static-analysis/assert-implementsInterface.php +++ b/tests/static-analysis/assert-implementsInterface.php @@ -10,51 +10,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return Serializable|class-string */ function implementsInterface(mixed $value) { - Assert::implementsInterface($value, Serializable::class); - - return $value; + return Assert::implementsInterface($value, Serializable::class); } /** * @psalm-pure * - * @param mixed $value - * * @return Serializable|class-string|null */ function nullOrImplementsInterface(mixed $value) { - Assert::nullOrImplementsInterface($value, Serializable::class); - - return $value; + return Assert::nullOrImplementsInterface($value, Serializable::class); } /** * @psalm-pure - * - * @param mixed $value */ function allImplementsInterface(mixed $value): iterable { - Assert::allImplementsInterface($value, Serializable::class); - - return $value; + return Assert::allImplementsInterface($value, Serializable::class); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrImplementsInterface(mixed $value): iterable { - Assert::allNullOrImplementsInterface($value, Serializable::class); - - return $value; + return Assert::allNullOrImplementsInterface($value, Serializable::class); } diff --git a/tests/static-analysis/assert-inArray.php b/tests/static-analysis/assert-inArray.php index 60f8dcc9..2b58a37e 100644 --- a/tests/static-analysis/assert-inArray.php +++ b/tests/static-analysis/assert-inArray.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ -function inArray($value, array $values): mixed +function inArray(mixed $value, array $values): mixed { - Assert::inArray($value, $values); - - return $value; + return Assert::inArray($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function nullOrInArray($value, array $values): mixed +function nullOrInArray(mixed $value, array $values): mixed { - Assert::nullOrInArray($value, $values); - - return $value; + return Assert::nullOrInArray($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function allInArray($value, array $values): mixed +function allInArray(mixed $value, array $values): mixed { - Assert::allInArray($value, $values); - - return $value; + return Assert::allInArray($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function allNullOrInArray($value, array $values): mixed +function allNullOrInArray(mixed $value, array $values): mixed { - Assert::allNullOrInArray($value, $values); - - return $value; + return Assert::allNullOrInArray($value, $values); } diff --git a/tests/static-analysis/assert-integer.php b/tests/static-analysis/assert-integer.php index 60efabce..49db520b 100644 --- a/tests/static-analysis/assert-integer.php +++ b/tests/static-analysis/assert-integer.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function integer(mixed $value): int { - Assert::integer($value); - - return $value; + return Assert::integer($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrInteger(mixed $value): ?int { - Assert::nullOrInteger($value); - - return $value; + return Assert::nullOrInteger($value); } /** * @psalm-pure - * - * @param mixed $value */ function allInteger(mixed $value): iterable { - Assert::allInteger($value); - - return $value; + return Assert::allInteger($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrInteger(mixed $value): iterable { - Assert::allNullOrInteger($value); - - return $value; + return Assert::allNullOrInteger($value); } diff --git a/tests/static-analysis/assert-integerish.php b/tests/static-analysis/assert-integerish.php index 5f80f1ae..023dc1cc 100644 --- a/tests/static-analysis/assert-integerish.php +++ b/tests/static-analysis/assert-integerish.php @@ -9,51 +9,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return numeric */ function integerish(mixed $value) { - Assert::integerish($value); - - return $value; + return Assert::integerish($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|numeric */ function nullOrIntegerish(mixed $value) { - Assert::nullOrIntegerish($value); - - return $value; + return Assert::nullOrIntegerish($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIntegerish(mixed $value): iterable { - Assert::allIntegerish($value); - - return $value; + return Assert::allIntegerish($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIntegerish(mixed $value): iterable { - Assert::allNullOrIntegerish($value); - - return $value; + return Assert::allNullOrIntegerish($value); } diff --git a/tests/static-analysis/assert-interfaceExists.php b/tests/static-analysis/assert-interfaceExists.php index 5f96cb8a..6f2d6f15 100644 --- a/tests/static-analysis/assert-interfaceExists.php +++ b/tests/static-analysis/assert-interfaceExists.php @@ -7,45 +7,37 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * * * @return class-string */ function interfaceExists(mixed $value): string { - Assert::interfaceExists($value); - - return $value; + return Assert::interfaceExists($value); } /** - * @param mixed $value + * * * @return null|class-string */ function nullOrInterfaceExists(mixed $value): ?string { - Assert::nullOrInterfaceExists($value); - - return $value; + return Assert::nullOrInterfaceExists($value); } /** - * @param mixed $value + * */ function allInterfaceExists(mixed $value): iterable { - Assert::allInterfaceExists($value); - - return $value; + return Assert::allInterfaceExists($value); } /** - * @param mixed $value + * */ function allNullOrInterfaceExists(mixed $value): iterable { - Assert::allNullOrInterfaceExists($value); - - return $value; + return Assert::allNullOrInterfaceExists($value); } diff --git a/tests/static-analysis/assert-ip.php b/tests/static-analysis/assert-ip.php index 6ce9f4c7..d1952f84 100644 --- a/tests/static-analysis/assert-ip.php +++ b/tests/static-analysis/assert-ip.php @@ -6,42 +6,28 @@ use Webmozart\Assert\Assert; -/** - * @param mixed $value - */ -function ip(mixed $value): mixed +function ip(string $value): string { - Assert::ip($value); - - return $value; + return Assert::ip($value); } -/** - * @param mixed $value - */ -function nullOrIp(mixed $value): mixed +function nullOrIp(?string $value): ?string { - Assert::nullOrIp($value); - - return $value; + return Assert::nullOrIp($value); } /** - * @param mixed $value + * @param iterable $value */ -function allIp(mixed $value): mixed +function allIp(iterable $value): iterable { - Assert::allIp($value); - - return $value; + return Assert::allIp($value); } /** - * @param mixed $value + * @param iterable $value */ -function allNullOrIp(mixed $value): mixed +function allNullOrIp(iterable $value): iterable { - Assert::allNullOrIp($value); - - return $value; + return Assert::allNullOrIp($value); } diff --git a/tests/static-analysis/assert-ipv4.php b/tests/static-analysis/assert-ipv4.php index 994e86f1..995bd0c6 100644 --- a/tests/static-analysis/assert-ipv4.php +++ b/tests/static-analysis/assert-ipv4.php @@ -6,42 +6,28 @@ use Webmozart\Assert\Assert; -/** - * @param mixed $value - */ -function ipv4($value): mixed +function ipv4(string $value): string { - Assert::ipv4($value); - - return $value; + return Assert::ipv4($value); } -/** - * @param mixed $value - */ -function nullOrIpv4($value): mixed +function nullOrIpv4(?string $value): ?string { - Assert::nullOrIpv4($value); - - return $value; + return Assert::nullOrIpv4($value); } /** - * @param mixed $value + * @param iterable $value */ -function allIpv4($value): mixed +function allIpv4(iterable $value): iterable { - Assert::allIpv4($value); - - return $value; + return Assert::allIpv4($value); } /** - * @param mixed $value + * @param iterable $value */ -function allNullOrIpv4($value): mixed +function allNullOrIpv4(iterable $value): iterable { - Assert::allNullOrIpv4($value); - - return $value; + return Assert::allNullOrIpv4($value); } diff --git a/tests/static-analysis/assert-ipv6.php b/tests/static-analysis/assert-ipv6.php index dc0b19db..a40d5b52 100644 --- a/tests/static-analysis/assert-ipv6.php +++ b/tests/static-analysis/assert-ipv6.php @@ -6,42 +6,28 @@ use Webmozart\Assert\Assert; -/** - * @param mixed $value - */ -function ipv6($value): mixed +function ipv6(string $value): string { - Assert::ipv6($value); - - return $value; + return Assert::ipv6($value); } -/** - * @param mixed $value - */ -function nullOrIpv6($value): mixed +function nullOrIpv6(?string $value): ?string { - Assert::nullOrIpv6($value); - - return $value; + return Assert::nullOrIpv6($value); } /** - * @param mixed $value + * @param iterable $value */ -function allIpv6($value): mixed +function allIpv6(iterable $value): iterable { - Assert::allIpv6($value); - - return $value; + return Assert::allIpv6($value); } /** - * @param mixed $value + * @param iterable $value */ -function allNullOrIpv6($value): mixed +function allNullOrIpv6(iterable $value): iterable { - Assert::allNullOrIpv6($value); - - return $value; + return Assert::allNullOrIpv6($value); } diff --git a/tests/static-analysis/assert-isAOf.php b/tests/static-analysis/assert-isAOf.php index cd3955ef..cef81395 100644 --- a/tests/static-analysis/assert-isAOf.php +++ b/tests/static-analysis/assert-isAOf.php @@ -16,9 +16,7 @@ */ function isAOf(mixed $value): mixed { - Assert::isAOf($value, Serializable::class); - - return $value; + return Assert::isAOf($value, Serializable::class); } /** @@ -30,9 +28,7 @@ function isAOf(mixed $value): mixed */ function nullOrIsAOf(mixed $value): mixed { - Assert::nullOrIsAOf($value, Serializable::class); - - return $value; + return Assert::nullOrIsAOf($value, Serializable::class); } /** @@ -44,9 +40,7 @@ function nullOrIsAOf(mixed $value): mixed */ function allIsAOf(mixed $value): iterable { - Assert::allIsAOf($value, Serializable::class); - - return $value; + return Assert::allIsAOf($value, Serializable::class); } /** @@ -58,7 +52,5 @@ function allIsAOf(mixed $value): iterable */ function allNullOrIsAOf(mixed $value): iterable { - Assert::allNullOrIsAOf($value, Serializable::class); - - return $value; + return Assert::allNullOrIsAOf($value, Serializable::class); } diff --git a/tests/static-analysis/assert-isAnyOf.php b/tests/static-analysis/assert-isAnyOf.php index bf7ec3e8..268f610d 100644 --- a/tests/static-analysis/assert-isAnyOf.php +++ b/tests/static-analysis/assert-isAnyOf.php @@ -12,11 +12,9 @@ * @param object|string $value * @param array $classes */ -function isAnyOf($value, array $classes): object|string +function isAnyOf(mixed $value, array $classes): object|string { - Assert::isAnyOf($value, $classes); - - return $value; + return Assert::isAnyOf($value, $classes); } /** @@ -25,11 +23,9 @@ function isAnyOf($value, array $classes): object|string * @param null|object|string $value * @param array $classes */ -function nullOrIsAnyOf($value, array $classes): object|string|null +function nullOrIsAnyOf(mixed $value, array $classes): object|string|null { - Assert::nullOrIsAnyOf($value, $classes); - - return $value; + return Assert::nullOrIsAnyOf($value, $classes); } /** @@ -38,11 +34,9 @@ function nullOrIsAnyOf($value, array $classes): object|string|null * @param iterable $value * @param array $classes */ -function allIsAnyOf($value, array $classes): iterable +function allIsAnyOf(mixed $value, array $classes): iterable { - Assert::allIsAnyOf($value, $classes); - - return $value; + return Assert::allIsAnyOf($value, $classes); } /** @@ -51,9 +45,7 @@ function allIsAnyOf($value, array $classes): iterable * @param iterable $value * @param array $classes */ -function allNullOrIsAnyOf($value, array $classes): iterable +function allNullOrIsAnyOf(mixed $value, array $classes): iterable { - Assert::allNullOrIsAnyOf($value, $classes); - - return $value; + return Assert::allNullOrIsAnyOf($value, $classes); } diff --git a/tests/static-analysis/assert-isArray.php b/tests/static-analysis/assert-isArray.php index 157e3fb4..76828646 100644 --- a/tests/static-analysis/assert-isArray.php +++ b/tests/static-analysis/assert-isArray.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function isArray(mixed $value): array { - Assert::isArray($value); - - return $value; + return Assert::isArray($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsArray(mixed $value): ?array { - Assert::nullOrIsArray($value); - - return $value; + return Assert::nullOrIsArray($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsArray(mixed $value): iterable { - Assert::allIsArray($value); - - return $value; + return Assert::allIsArray($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsArray(mixed $value): iterable { - Assert::allNullOrIsArray($value); - - return $value; + return Assert::allNullOrIsArray($value); } diff --git a/tests/static-analysis/assert-isArrayAccessible.php b/tests/static-analysis/assert-isArrayAccessible.php index 725e383a..6989b74e 100644 --- a/tests/static-analysis/assert-isArrayAccessible.php +++ b/tests/static-analysis/assert-isArrayAccessible.php @@ -9,48 +9,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function isArrayAccessible(mixed $value): array|ArrayAccess { - Assert::isArrayAccessible($value); - - return $value; + return Assert::isArrayAccessible($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsArrayAccessible(mixed $value): array|ArrayAccess|null { - Assert::nullOrIsArrayAccessible($value); - - return $value; + return Assert::nullOrIsArrayAccessible($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsArrayAccessible(mixed $value): iterable { - Assert::allIsArrayAccessible($value); - - return $value; + return Assert::allIsArrayAccessible($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsArrayAccessible(mixed $value): iterable { - Assert::allNullOrIsArrayAccessible($value); - - return $value; + return Assert::allNullOrIsArrayAccessible($value); } diff --git a/tests/static-analysis/assert-isCallable.php b/tests/static-analysis/assert-isCallable.php index 4f91156b..62a733f8 100644 --- a/tests/static-analysis/assert-isCallable.php +++ b/tests/static-analysis/assert-isCallable.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function isCallable(mixed $value): callable { - Assert::isCallable($value); - - return $value; + return Assert::isCallable($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsCallable(mixed $value): ?callable { - Assert::nullOrIsCallable($value); - - return $value; + return Assert::nullOrIsCallable($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsCallable(mixed $value): iterable { - Assert::allIsCallable($value); - - return $value; + return Assert::allIsCallable($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsCallable(mixed $value): iterable { - Assert::allNullOrIsCallable($value); - - return $value; + return Assert::allNullOrIsCallable($value); } diff --git a/tests/static-analysis/assert-isCountable.php b/tests/static-analysis/assert-isCountable.php index c1d4a68b..c5024bbb 100644 --- a/tests/static-analysis/assert-isCountable.php +++ b/tests/static-analysis/assert-isCountable.php @@ -4,57 +4,41 @@ namespace Webmozart\Assert\Tests\StaticAnalysis; -use countable; +use Countable; use Webmozart\Assert\Assert; /** * @psalm-pure - * - * @param mixed $value */ function isCountable(mixed $value): Countable { - Assert::isCountable($value); - - return $value; + return Assert::isCountable($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsCountable(mixed $value): ?Countable { - Assert::nullOrIsCountable($value); - - return $value; + return Assert::nullOrIsCountable($value); } /** * @psalm-pure * - * @param mixed $value - * - * @return iterable + * @return iterable */ function allIsCountable(mixed $value) { - Assert::allIsCountable($value); - - return $value; + return Assert::allIsCountable($value); } /** * @psalm-pure * - * @param mixed $value - * - * @return iterable + * @return iterable */ function allNullOrIsCountable(mixed $value) { - Assert::allNullOrIsCountable($value); - - return $value; + return Assert::allNullOrIsCountable($value); } diff --git a/tests/static-analysis/assert-isEmpty.php b/tests/static-analysis/assert-isEmpty.php index b7e1af61..281a33d4 100644 --- a/tests/static-analysis/assert-isEmpty.php +++ b/tests/static-analysis/assert-isEmpty.php @@ -11,9 +11,7 @@ */ function isEmptyNullableObject(?object $value): null { - Assert::isEmpty($value); - - return $value; + return Assert::isEmpty($value); } /** @@ -23,9 +21,7 @@ function isEmptyNullableObject(?object $value): null */ function isEmptyString(string $value) { - Assert::isEmpty($value); - - return $value; + return Assert::isEmpty($value); } /** @@ -35,9 +31,7 @@ function isEmptyString(string $value) */ function isEmptyInt(int $value) { - Assert::isEmpty($value); - - return $value; + return Assert::isEmpty($value); } /** @@ -47,9 +41,7 @@ function isEmptyInt(int $value) */ function isEmptyBool(bool $value) { - Assert::isEmpty($value); - - return $value; + return Assert::isEmpty($value); } /** @@ -59,43 +51,31 @@ function isEmptyBool(bool $value) */ function isEmptyArray(array $value) { - Assert::isEmpty($value); - - return $value; + return Assert::isEmpty($value); } /** * @psalm-pure * - * @return null|empty + * @return null */ -function nullOrIsEmpty(?object $value) +function nullOrIsEmpty(?object $value): null { - Assert::nullOrIsEmpty($value); - - return $value; + return Assert::nullOrIsEmpty($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsEmpty(mixed $value): iterable { - Assert::allIsEmpty($value); - - return $value; + return Assert::allIsEmpty($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsEmpty(mixed $value): iterable { - Assert::allNullOrIsEmpty($value); - - return $value; + return Assert::allNullOrIsEmpty($value); } diff --git a/tests/static-analysis/assert-isInitialized.php b/tests/static-analysis/assert-isInitialized.php index bc89240d..054aba97 100644 --- a/tests/static-analysis/assert-isInitialized.php +++ b/tests/static-analysis/assert-isInitialized.php @@ -8,12 +8,8 @@ /** * @psalm-pure - * - * @param object $value */ function isInitialized(mixed $value, string $property): object { - Assert::isInitialized($value, $property); - - return $value; + return Assert::isInitialized($value, $property); } diff --git a/tests/static-analysis/assert-isInstanceOf.php b/tests/static-analysis/assert-isInstanceOf.php index a07a2089..810a3a7a 100644 --- a/tests/static-analysis/assert-isInstanceOf.php +++ b/tests/static-analysis/assert-isInstanceOf.php @@ -9,48 +9,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function isInstanceOf(mixed $value): Serializable { - Assert::isInstanceOf($value, Serializable::class); - - return $value; + return Assert::isInstanceOf($value, Serializable::class); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsInstanceOf(mixed $value): ?Serializable { - Assert::nullOrIsInstanceOf($value, Serializable::class); - - return $value; + return Assert::nullOrIsInstanceOf($value, Serializable::class); } /** * @psalm-pure - * - * @param mixed $value */ function allIsInstanceOf(mixed $value): iterable { - Assert::allIsInstanceOf($value, Serializable::class); - - return $value; + return Assert::allIsInstanceOf($value, Serializable::class); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsInstanceOf(mixed $value): iterable { - Assert::allNullOrIsInstanceOf($value, Serializable::class); - - return $value; + return Assert::allNullOrIsInstanceOf($value, Serializable::class); } diff --git a/tests/static-analysis/assert-isInstanceOfAny.php b/tests/static-analysis/assert-isInstanceOfAny.php index 5274b72e..d432fe5f 100644 --- a/tests/static-analysis/assert-isInstanceOfAny.php +++ b/tests/static-analysis/assert-isInstanceOfAny.php @@ -7,45 +7,37 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * @param object $value * @param array $classes */ -function isInstanceOfAny($value, array $classes): mixed +function isInstanceOfAny(object $value, array $classes): object { - Assert::isInstanceOfAny($value, $classes); - - return $value; + return Assert::isInstanceOfAny($value, $classes); } /** - * @param mixed $value + * @param object|null $value * @param array $classes */ -function nullOrIsInstanceOfAny($value, array $classes): mixed +function nullOrIsInstanceOfAny(?object $value, array $classes): ?object { - Assert::nullOrIsInstanceOfAny($value, $classes); - - return $value; + return Assert::nullOrIsInstanceOfAny($value, $classes); } /** - * @param mixed $value + * @param iterable $value * @param array $classes */ -function allIsInstanceOfAny($value, array $classes): mixed +function allIsInstanceOfAny(iterable $value, array $classes): iterable { - Assert::allIsInstanceOfAny($value, $classes); - - return $value; + return Assert::allIsInstanceOfAny($value, $classes); } /** - * @param mixed $value + * @param iterable $value * @param array $classes */ -function allNullOrIsInstanceOfAny($value, array $classes): mixed +function allNullOrIsInstanceOfAny(iterable $value, array $classes): iterable { - Assert::allNullOrIsInstanceOfAny($value, $classes); - - return $value; + return Assert::allNullOrIsInstanceOfAny($value, $classes); } diff --git a/tests/static-analysis/assert-isIterable.php b/tests/static-analysis/assert-isIterable.php index 6e9488b2..bbec7866 100644 --- a/tests/static-analysis/assert-isIterable.php +++ b/tests/static-analysis/assert-isIterable.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function isIterable(mixed $value): iterable { - Assert::isIterable($value); - - return $value; + return Assert::isIterable($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrIsIterable(mixed $value): ?iterable { - Assert::nullOrIsIterable($value); - - return $value; + return Assert::nullOrIsIterable($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsIterable(mixed $value): iterable { - Assert::allIsIterable($value); - - return $value; + return Assert::allIsIterable($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsIterable(mixed $value): iterable { - Assert::allNullOrIsIterable($value); - - return $value; + return Assert::allNullOrIsIterable($value); } diff --git a/tests/static-analysis/assert-isList.php b/tests/static-analysis/assert-isList.php index 46e7fd13..7c601a96 100644 --- a/tests/static-analysis/assert-isList.php +++ b/tests/static-analysis/assert-isList.php @@ -10,15 +10,11 @@ /** * @psalm-pure * - * @param mixed $value - * * @return list */ function isList(mixed $value): array { - Assert::isList($value); - - return $value; + return Assert::isList($value); } /** @@ -30,45 +26,31 @@ function isList(mixed $value): array */ function isListWithKnownType(array $value): array { - Assert::isList($value); - - return $value; + return Assert::isList($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|list */ function nullOrIsList(mixed $value): ?array { - Assert::nullOrIsList($value); - - return $value; + return Assert::nullOrIsList($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsList(mixed $value): iterable { - Assert::allIsList($value); - - return $value; + return Assert::allIsList($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsList(mixed $value): iterable { - Assert::allNullOrIsList($value); - - return $value; + return Assert::allNullOrIsList($value); } diff --git a/tests/static-analysis/assert-isMap.php b/tests/static-analysis/assert-isMap.php index f8c14f16..f1367c73 100644 --- a/tests/static-analysis/assert-isMap.php +++ b/tests/static-analysis/assert-isMap.php @@ -10,15 +10,11 @@ /** * @psalm-pure * - * @param mixed $value - * * @return array */ function isMap(mixed $value): array { - Assert::isMap($value); - - return $value; + return Assert::isMap($value); } /** @@ -32,38 +28,29 @@ function isMap(mixed $value): array */ function isMapWithKnownType(array $value): array { - Assert::isMap($value); - - return $value; + return Assert::isMap($value); } /** * @psalm-pure * - * @param array $value - * * @return array */ -function isMapWithEmptyArray(array $value): array +function isMapWithEmptyArray(): array { - Assert::isMap($value); - Assert::isEmpty($value); + $value = []; - return $value; + return Assert::isMap($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|array */ function nullOrIsMap(mixed $value): ?array { - Assert::nullOrIsMap($value); - - return $value; + return Assert::nullOrIsMap($value); } /** @@ -73,9 +60,7 @@ function nullOrIsMap(mixed $value): ?array */ function allIsMap(iterable $value): iterable { - Assert::allIsMap($value); - - return $value; + return Assert::allIsMap($value); } /** @@ -85,7 +70,5 @@ function allIsMap(iterable $value): iterable */ function allNullOrIsMap(iterable $value): iterable { - Assert::allNullOrIsMap($value); - - return $value; + return Assert::allNullOrIsMap($value); } diff --git a/tests/static-analysis/assert-isNonEmptyList.php b/tests/static-analysis/assert-isNonEmptyList.php index 61325674..5f21141f 100644 --- a/tests/static-analysis/assert-isNonEmptyList.php +++ b/tests/static-analysis/assert-isNonEmptyList.php @@ -9,63 +9,45 @@ /** * @psalm-pure * - * @param mixed $value - * * @return non-empty-list */ function isNonEmptyList(mixed $value): array { - Assert::isNonEmptyList($value); - - return $value; + return Assert::isNonEmptyList($value); } /** * @psalm-pure + * + * @param array $value */ -function isNonEmptyListWithRange(): mixed +function isNonEmptyListWithRange(array $value): array { - $value = range(1, 100); - - Assert::isNonEmptyList($value); - - return $value[0]; + return Assert::isNonEmptyList($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|non-empty-list */ function nullOrIsNonEmptyList(mixed $value): ?array { - Assert::nullOrIsNonEmptyList($value); - - return $value; + return Assert::nullOrIsNonEmptyList($value); } /** * @psalm-pure - * - * @param mixed $value */ function allIsNonEmptyList(mixed $value): iterable { - Assert::allIsNonEmptyList($value); - - return $value; + return Assert::allIsNonEmptyList($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrIsNonEmptyList(mixed $value): iterable { - Assert::allNullOrIsNonEmptyList($value); - - return $value; + return Assert::allNullOrIsNonEmptyList($value); } diff --git a/tests/static-analysis/assert-isNonEmptyMap.php b/tests/static-analysis/assert-isNonEmptyMap.php index 1942f93d..bb80f8a7 100644 --- a/tests/static-analysis/assert-isNonEmptyMap.php +++ b/tests/static-analysis/assert-isNonEmptyMap.php @@ -10,15 +10,13 @@ /** * @psalm-pure * - * @param mixed $value + * @param array $value * * @return non-empty-array */ -function isNonEmptyMap(mixed $value): array +function isNonEmptyMap(array $value): array { - Assert::isNonEmptyMap($value); - - return $value; + return Assert::isNonEmptyMap($value); } /** @@ -26,49 +24,41 @@ function isNonEmptyMap(mixed $value): array * * @psalm-pure * - * @param array $value + * @param array $value * - * @return array + * @return non-empty-array */ function isNonEmptyMapWithKnownType(array $value): array { - Assert::isNonEmptyMap($value); - - return $value; + return Assert::isNonEmptyMap($value); } /** * @psalm-pure * - * @param mixed $value + * @param array|null $value */ -function nullOrIsNonEmptyMap(mixed $value): mixed +function nullOrIsNonEmptyMap(?array $value): ?array { - Assert::nullOrIsNonEmptyMap($value); - - return $value; + return Assert::nullOrIsNonEmptyMap($value); } /** * @psalm-pure * - * @param iterable> $value + * @param iterable> $value */ function allIsNonEmptyMap(iterable $value): iterable { - Assert::allIsNonEmptyMap($value); - - return $value; + return Assert::allIsNonEmptyMap($value); } /** * @psalm-pure * - * @param iterable> $value + * @param iterable|null> $value */ function allNullOrIsNonEmptyMap(iterable $value): iterable { - Assert::allNullOrIsNonEmptyMap($value); - - return $value; + return Assert::allNullOrIsNonEmptyMap($value); } diff --git a/tests/static-analysis/assert-isNotA.php b/tests/static-analysis/assert-isNotA.php index 1e8f9df5..506cd426 100644 --- a/tests/static-analysis/assert-isNotA.php +++ b/tests/static-analysis/assert-isNotA.php @@ -5,56 +5,47 @@ namespace Webmozart\Assert\Tests\StaticAnalysis; use DateTime; -use stdClass; use Webmozart\Assert\Assert; /** * @psalm-pure * - * @param stdClass|DateTime $value + * @psalm-return object|class-string */ -function isNotA(object $value): stdClass +function isNotA(mixed $value): object|string { - Assert::isNotA($value, DateTime::class); - - return $value; + return Assert::isNotA($value, DateTime::class); } /** * @psalm-pure * * @param null|object|string $value - * @param class-string $class + * @param class-string $class */ -function nullOrIsNotA($value, $class): object|string|null +function nullOrIsNotA(mixed $value, $class): object|string|null { - Assert::nullOrIsNotA($value, $class); - - return $value; + return Assert::nullOrIsNotA($value, $class); } /** * @psalm-pure * * @param iterable $value - * @param class-string $class + * @param class-string $class */ -function allIsNotA($value, $class): iterable +function allIsNotA(mixed $value, $class): iterable { - Assert::allIsNotA($value, $class); - - return $value; + return Assert::allIsNotA($value, $class); } /** * @psalm-pure * * @param iterable $value - * @param class-string $class + * @param class-string $class */ -function allNullOrIsNotA($value, $class): iterable +function allNullOrIsNotA(mixed $value, $class): iterable { - Assert::allNullOrIsNotA($value, $class); - - return $value; + return Assert::allNullOrIsNotA($value, $class); } diff --git a/tests/static-analysis/assert-isNotInstanceOfAny.php b/tests/static-analysis/assert-isNotInstanceOfAny.php index a55e558b..ff8e483b 100644 --- a/tests/static-analysis/assert-isNotInstanceOfAny.php +++ b/tests/static-analysis/assert-isNotInstanceOfAny.php @@ -7,45 +7,37 @@ use Webmozart\Assert\Assert; /** - * @param mixed $value + * * @param array $classes */ -function isNotInstanceOfAny($value, array $classes): mixed +function isNotInstanceOfAny(mixed $value, array $classes): mixed { - Assert::isNotInstanceOfAny($value, $classes); - - return $value; + return Assert::isNotInstanceOfAny($value, $classes); } /** - * @param mixed $value + * * @param array $classes */ -function nullOrIsNotInstanceOfAny($value, array $classes): mixed +function nullOrIsNotInstanceOfAny(mixed $value, array $classes): mixed { - Assert::nullOrIsNotInstanceOfAny($value, $classes); - - return $value; + return Assert::nullOrIsNotInstanceOfAny($value, $classes); } /** - * @param mixed $value + * @param iterable $value * @param array $classes */ -function allIsNotInstanceOfAny($value, array $classes): mixed +function allIsNotInstanceOfAny(iterable $value, array $classes): iterable { - Assert::allIsNotInstanceOfAny($value, $classes); - - return $value; + return Assert::allIsNotInstanceOfAny($value, $classes); } /** - * @param mixed $value + * @param iterable $value * @param array $classes */ -function allNullOrIsNotInstanceOfAny($value, array $classes): mixed +function allNullOrIsNotInstanceOfAny(iterable $value, array $classes): iterable { - Assert::allNullOrIsNotInstanceOfAny($value, $classes); - - return $value; + return Assert::allNullOrIsNotInstanceOfAny($value, $classes); } diff --git a/tests/static-analysis/assert-isStatic.php b/tests/static-analysis/assert-isStatic.php index d0520884..31854610 100644 --- a/tests/static-analysis/assert-isStatic.php +++ b/tests/static-analysis/assert-isStatic.php @@ -2,13 +2,9 @@ namespace Webmozart\Assert\Tests\StaticAnalysis; -use Closure; use Webmozart\Assert\Assert; -/** - * @return Closure|callable-string - */ -function isStatic(mixed $closure): Closure|string +function isStatic(callable $closure): callable { return Assert::isStatic($closure); } diff --git a/tests/static-analysis/assert-keyExists.php b/tests/static-analysis/assert-keyExists.php index 39b7dc18..222ebf40 100644 --- a/tests/static-analysis/assert-keyExists.php +++ b/tests/static-analysis/assert-keyExists.php @@ -13,9 +13,7 @@ */ function keyExists(array $array, $key): array { - Assert::keyExists($array, $key); - - return $array; + return Assert::keyExists($array, $key); } /** @@ -25,9 +23,7 @@ function keyExists(array $array, $key): array */ function nullOrKeyExists(?array $array, $key): ?array { - Assert::nullOrKeyExists($array, $key); - - return $array; + return Assert::nullOrKeyExists($array, $key); } /** @@ -38,9 +34,7 @@ function nullOrKeyExists(?array $array, $key): ?array */ function allKeyExists(iterable $array, $key): iterable { - Assert::allKeyExists($array, $key); - - return $array; + return Assert::allKeyExists($array, $key); } /** @@ -51,7 +45,5 @@ function allKeyExists(iterable $array, $key): iterable */ function allNullOrKeyExists(iterable $array, $key): iterable { - Assert::allNullOrKeyExists($array, $key); - - return $array; + return Assert::allNullOrKeyExists($array, $key); } diff --git a/tests/static-analysis/assert-keyNotExists.php b/tests/static-analysis/assert-keyNotExists.php index fd81821c..0f5c9eab 100644 --- a/tests/static-analysis/assert-keyNotExists.php +++ b/tests/static-analysis/assert-keyNotExists.php @@ -13,9 +13,7 @@ */ function keyNotExists(array $array, $key): array { - Assert::keyNotExists($array, $key); - - return $array; + return Assert::keyNotExists($array, $key); } /** @@ -25,9 +23,7 @@ function keyNotExists(array $array, $key): array */ function nullOrKeyNotExists(?array $array, $key): ?array { - Assert::nullOrKeyNotExists($array, $key); - - return $array; + return Assert::nullOrKeyNotExists($array, $key); } /** @@ -38,9 +34,7 @@ function nullOrKeyNotExists(?array $array, $key): ?array */ function allKeyNotExists(iterable $array, $key): iterable { - Assert::allKeyNotExists($array, $key); - - return $array; + return Assert::allKeyNotExists($array, $key); } /** @@ -51,7 +45,5 @@ function allKeyNotExists(iterable $array, $key): iterable */ function allNullOrKeyNotExists(iterable $array, $key): iterable { - Assert::allNullOrKeyNotExists($array, $key); - - return $array; + return Assert::allNullOrKeyNotExists($array, $key); } diff --git a/tests/static-analysis/assert-length.php b/tests/static-analysis/assert-length.php index 339aa2a5..7fa32c51 100644 --- a/tests/static-analysis/assert-length.php +++ b/tests/static-analysis/assert-length.php @@ -11,9 +11,7 @@ */ function length(string $value, int $length): string { - Assert::length($value, $length); - - return $value; + return Assert::length($value, $length); } /** @@ -21,9 +19,7 @@ function length(string $value, int $length): string */ function nullOrLength(?string $value, int $length): ?string { - Assert::nullOrLength($value, $length); - - return $value; + return Assert::nullOrLength($value, $length); } /** @@ -33,9 +29,7 @@ function nullOrLength(?string $value, int $length): ?string */ function allLength(iterable $value, int $length): iterable { - Assert::allLength($value, $length); - - return $value; + return Assert::allLength($value, $length); } /** @@ -45,7 +39,5 @@ function allLength(iterable $value, int $length): iterable */ function allNullOrLength(iterable $value, int $length): iterable { - Assert::allNullOrLength($value, $length); - - return $value; + return Assert::allNullOrLength($value, $length); } diff --git a/tests/static-analysis/assert-lengthBetween.php b/tests/static-analysis/assert-lengthBetween.php index 2e096ccc..8d67099c 100644 --- a/tests/static-analysis/assert-lengthBetween.php +++ b/tests/static-analysis/assert-lengthBetween.php @@ -11,9 +11,7 @@ */ function lengthBetween(string $value, int $min, int $max): string { - Assert::lengthBetween($value, $min, $max); - - return $value; + return Assert::lengthBetween($value, $min, $max); } /** @@ -21,9 +19,7 @@ function lengthBetween(string $value, int $min, int $max): string */ function nullOrLengthBetween(?string $value, int $min, int $max): ?string { - Assert::nullOrLengthBetween($value, $min, $max); - - return $value; + return Assert::nullOrLengthBetween($value, $min, $max); } /** @@ -35,9 +31,7 @@ function nullOrLengthBetween(?string $value, int $min, int $max): ?string */ function allLengthBetween(iterable $value, int $min, int $max): iterable { - Assert::allLengthBetween($value, $min, $max); - - return $value; + return Assert::allLengthBetween($value, $min, $max); } /** @@ -49,7 +43,5 @@ function allLengthBetween(iterable $value, int $min, int $max): iterable */ function allNullOrLengthBetween(iterable $value, int $min, int $max): iterable { - Assert::allNullOrLengthBetween($value, $min, $max); - - return $value; + return Assert::allNullOrLengthBetween($value, $min, $max); } diff --git a/tests/static-analysis/assert-lessThan.php b/tests/static-analysis/assert-lessThan.php index 2d3a84e6..2e68a6d6 100644 --- a/tests/static-analysis/assert-lessThan.php +++ b/tests/static-analysis/assert-lessThan.php @@ -8,52 +8,36 @@ /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function lessThan($value, $limit): mixed +function lessThan(mixed $value, mixed $limit): mixed { - Assert::lessThan($value, $limit); - - return $value; + return Assert::lessThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function nullOrLessThan($value, $limit): mixed +function nullOrLessThan(mixed $value, mixed $limit): mixed { - Assert::nullOrLessThan($value, $limit); - - return $value; + return Assert::nullOrLessThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allLessThan($value, $limit): mixed +function allLessThan(mixed $value, mixed $limit): mixed { - Assert::allLessThan($value, $limit); - - return $value; + return Assert::allLessThan($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allNullOrLessThan($value, $limit): mixed +function allNullOrLessThan(mixed $value, mixed $limit): mixed { - Assert::allNullOrLessThan($value, $limit); - - return $value; + return Assert::allNullOrLessThan($value, $limit); } diff --git a/tests/static-analysis/assert-lessThanEq.php b/tests/static-analysis/assert-lessThanEq.php index 1b7f5214..df4d529f 100644 --- a/tests/static-analysis/assert-lessThanEq.php +++ b/tests/static-analysis/assert-lessThanEq.php @@ -8,52 +8,36 @@ /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function lessThanEq($value, $limit): mixed +function lessThanEq(mixed $value, mixed $limit): mixed { - Assert::lessThanEq($value, $limit); - - return $value; + return Assert::lessThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function nullOrLessThanEq($value, $limit): mixed +function nullOrLessThanEq(mixed $value, mixed $limit): mixed { - Assert::nullOrLessThanEq($value, $limit); - - return $value; + return Assert::nullOrLessThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allLessThanEq($value, $limit): mixed +function allLessThanEq(mixed $value, mixed $limit): mixed { - Assert::allLessThanEq($value, $limit); - - return $value; + return Assert::allLessThanEq($value, $limit); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $limit */ -function allNullOrLessThanEq($value, $limit): mixed +function allNullOrLessThanEq(mixed $value, mixed $limit): mixed { - Assert::allNullOrLessThanEq($value, $limit); - - return $value; + return Assert::allNullOrLessThanEq($value, $limit); } diff --git a/tests/static-analysis/assert-lower.php b/tests/static-analysis/assert-lower.php index 2834cf8f..4bef1f8e 100644 --- a/tests/static-analysis/assert-lower.php +++ b/tests/static-analysis/assert-lower.php @@ -13,9 +13,7 @@ */ function lower(string $value): string { - Assert::lower($value); - - return $value; + return Assert::lower($value); } /** @@ -25,9 +23,7 @@ function lower(string $value): string */ function nullOrLower(?string $value): ?string { - Assert::nullOrLower($value); - - return $value; + return Assert::nullOrLower($value); } /** @@ -37,9 +33,7 @@ function nullOrLower(?string $value): ?string */ function allLower(iterable $value): iterable { - Assert::allLower($value); - - return $value; + return Assert::allLower($value); } /** @@ -49,7 +43,5 @@ function allLower(iterable $value): iterable */ function allNullOrLower(iterable $value): iterable { - Assert::allNullOrLower($value); - - return $value; + return Assert::allNullOrLower($value); } diff --git a/tests/static-analysis/assert-maxCount.php b/tests/static-analysis/assert-maxCount.php index fa6b1220..d9702fca 100644 --- a/tests/static-analysis/assert-maxCount.php +++ b/tests/static-analysis/assert-maxCount.php @@ -11,22 +11,18 @@ * @param Countable|array $array * @param int|float $max */ -function maxCount($array, $max): Countable|array +function maxCount(mixed $array, $max): Countable|array { - Assert::maxCount($array, $max); - - return $array; + return Assert::maxCount($array, $max); } /** * @param null|Countable|array $array * @param int|float $max */ -function nullOrMaxCount($array, $max): Countable|array|null +function nullOrMaxCount(mixed $array, $max): Countable|array|null { - Assert::nullOrMaxCount($array, $max); - - return $array; + return Assert::nullOrMaxCount($array, $max); } /** @@ -35,9 +31,7 @@ function nullOrMaxCount($array, $max): Countable|array|null */ function allMaxCount(iterable $array, $max): iterable { - Assert::allMaxCount($array, $max); - - return $array; + return Assert::allMaxCount($array, $max); } /** @@ -46,7 +40,5 @@ function allMaxCount(iterable $array, $max): iterable */ function allNullOrMaxCount(iterable $array, $max): iterable { - Assert::allNullOrMaxCount($array, $max); - - return $array; + return Assert::allNullOrMaxCount($array, $max); } diff --git a/tests/static-analysis/assert-maxLength.php b/tests/static-analysis/assert-maxLength.php index 3534a0d2..508e2e4f 100644 --- a/tests/static-analysis/assert-maxLength.php +++ b/tests/static-analysis/assert-maxLength.php @@ -11,9 +11,7 @@ */ function maxLength(string $value, int $max): string { - Assert::maxLength($value, $max); - - return $value; + return Assert::maxLength($value, $max); } /** @@ -21,9 +19,7 @@ function maxLength(string $value, int $max): string */ function nullOrMaxLength(?string $value, int $max): ?string { - Assert::nullOrMaxLength($value, $max); - - return $value; + return Assert::nullOrMaxLength($value, $max); } /** @@ -35,9 +31,7 @@ function nullOrMaxLength(?string $value, int $max): ?string */ function allMaxLength(iterable $value, int $max): iterable { - Assert::allMaxLength($value, $max); - - return $value; + return Assert::allMaxLength($value, $max); } /** @@ -49,7 +43,5 @@ function allMaxLength(iterable $value, int $max): iterable */ function allNullOrMaxLength(iterable $value, int $max): iterable { - Assert::allMaxLength($value, $max); - - return $value; + return Assert::allMaxLength($value, $max); } diff --git a/tests/static-analysis/assert-methodExists.php b/tests/static-analysis/assert-methodExists.php index a3a19dde..6670a7a3 100644 --- a/tests/static-analysis/assert-methodExists.php +++ b/tests/static-analysis/assert-methodExists.php @@ -12,11 +12,9 @@ * @param class-string|object $classOrObject * @param mixed $method */ -function methodExists($classOrObject, $method): string|object +function methodExists(mixed $classOrObject, $method): string|object { - Assert::methodExists($classOrObject, $method); - - return $classOrObject; + return Assert::methodExists($classOrObject, $method); } /** @@ -25,11 +23,9 @@ function methodExists($classOrObject, $method): string|object * @param null|class-string|object $classOrObject * @param mixed $method */ -function nullOrMethodExists($classOrObject, $method): string|object|null +function nullOrMethodExists(mixed $classOrObject, $method): string|object|null { - Assert::nullOrMethodExists($classOrObject, $method); - - return $classOrObject; + return Assert::nullOrMethodExists($classOrObject, $method); } /** @@ -40,9 +36,7 @@ function nullOrMethodExists($classOrObject, $method): string|object|null */ function allMethodExists(iterable $classOrObject, $method): iterable { - Assert::allMethodExists($classOrObject, $method); - - return $classOrObject; + return Assert::allMethodExists($classOrObject, $method); } /** @@ -53,7 +47,5 @@ function allMethodExists(iterable $classOrObject, $method): iterable */ function allNullOrMethodExists(iterable $classOrObject, $method): iterable { - Assert::allNullOrMethodExists($classOrObject, $method); - - return $classOrObject; + return Assert::allNullOrMethodExists($classOrObject, $method); } diff --git a/tests/static-analysis/assert-methodNotExists.php b/tests/static-analysis/assert-methodNotExists.php index 9beb711a..b51cbfa4 100644 --- a/tests/static-analysis/assert-methodNotExists.php +++ b/tests/static-analysis/assert-methodNotExists.php @@ -12,11 +12,9 @@ * @param class-string|object $classOrObject * @param mixed $method */ -function methodNotExists($classOrObject, $method): string|object +function methodNotExists(mixed $classOrObject, $method): string|object { - Assert::methodNotExists($classOrObject, $method); - - return $classOrObject; + return Assert::methodNotExists($classOrObject, $method); } /** @@ -25,11 +23,9 @@ function methodNotExists($classOrObject, $method): string|object * @param null|class-string|object $classOrObject * @param mixed $method */ -function nullOrMethodNotExists($classOrObject, $method): string|object|null +function nullOrMethodNotExists(mixed $classOrObject, $method): string|object|null { - Assert::nullOrMethodNotExists($classOrObject, $method); - - return $classOrObject; + return Assert::nullOrMethodNotExists($classOrObject, $method); } /** @@ -40,9 +36,7 @@ function nullOrMethodNotExists($classOrObject, $method): string|object|null */ function allMethodNotExists(iterable $classOrObject, $method): iterable { - Assert::allMethodNotExists($classOrObject, $method); - - return $classOrObject; + return Assert::allMethodNotExists($classOrObject, $method); } /** @@ -53,7 +47,5 @@ function allMethodNotExists(iterable $classOrObject, $method): iterable */ function allNullOrMethodNotExists(iterable $classOrObject, $method): iterable { - Assert::allNullOrMethodNotExists($classOrObject, $method); - - return $classOrObject; + return Assert::allNullOrMethodNotExists($classOrObject, $method); } diff --git a/tests/static-analysis/assert-minCount.php b/tests/static-analysis/assert-minCount.php index c2498ec6..d7e323a4 100644 --- a/tests/static-analysis/assert-minCount.php +++ b/tests/static-analysis/assert-minCount.php @@ -11,22 +11,18 @@ * @param Countable|array $array * @param int|float $min */ -function minCount($array, $min): Countable|array +function minCount(mixed $array, $min): Countable|array { - Assert::minCount($array, $min); - - return $array; + return Assert::minCount($array, $min); } /** * @param null|Countable|array $array * @param int|float $min */ -function nullOrMinCount($array, $min): Countable|array|null +function nullOrMinCount(mixed $array, $min): Countable|array|null { - Assert::nullOrMinCount($array, $min); - - return $array; + return Assert::nullOrMinCount($array, $min); } /** @@ -35,11 +31,9 @@ function nullOrMinCount($array, $min): Countable|array|null * * @return iterable */ -function allMinCount($array, $min) +function allMinCount(mixed $array, $min) { - Assert::allMinCount($array, $min); - - return $array; + return Assert::allMinCount($array, $min); } /** @@ -48,9 +42,7 @@ function allMinCount($array, $min) * * @return iterable */ -function allNullOrMinCount($array, $min) +function allNullOrMinCount(mixed $array, $min) { - Assert::allNullOrMinCount($array, $min); - - return $array; + return Assert::allNullOrMinCount($array, $min); } diff --git a/tests/static-analysis/assert-minLength.php b/tests/static-analysis/assert-minLength.php index 03e3537f..303e9469 100644 --- a/tests/static-analysis/assert-minLength.php +++ b/tests/static-analysis/assert-minLength.php @@ -13,9 +13,7 @@ */ function minLength(string $value, $min): string { - Assert::minLength($value, $min); - - return $value; + return Assert::minLength($value, $min); } /** @@ -25,9 +23,7 @@ function minLength(string $value, $min): string */ function nullOrMinLength(?string $value, $min): ?string { - Assert::nullOrMinLength($value, $min); - - return $value; + return Assert::nullOrMinLength($value, $min); } /** @@ -38,9 +34,7 @@ function nullOrMinLength(?string $value, $min): ?string */ function allMinLength(iterable $value, $min): iterable { - Assert::allMinLength($value, $min); - - return $value; + return Assert::allMinLength($value, $min); } /** @@ -51,7 +45,5 @@ function allMinLength(iterable $value, $min): iterable */ function allNullOrMinLength(iterable $value, $min): iterable { - Assert::allNullOrMinLength($value, $min); - - return $value; + return Assert::allNullOrMinLength($value, $min); } diff --git a/tests/static-analysis/assert-natural.php b/tests/static-analysis/assert-natural.php index 3c7b3369..4928d767 100644 --- a/tests/static-analysis/assert-natural.php +++ b/tests/static-analysis/assert-natural.php @@ -9,57 +9,39 @@ /** * @psalm-pure * - * @param mixed $value - * * @psalm-return positive-int|0 */ function natural(mixed $value): int { - Assert::natural($value); - - return $value; + return Assert::natural($value); } /** * @psalm-pure * - * @param mixed $value - * * @psalm-return positive-int|0|null */ function nullOrNatural(mixed $value): ?int { - Assert::nullOrNatural($value); - - return $value; + return Assert::nullOrNatural($value); } /** * @psalm-pure * - * @param mixed $value - * * - * @psalm-suppress MixedInferredReturnType https://github.com/vimeo/psalm/issues/5052 - * @psalm-suppress MixedReturnStatement https://github.com/vimeo/psalm/issues/5052 + * @return iterable */ function allNatural(mixed $value): iterable { - Assert::allNatural($value); - - return $value; + return Assert::allNatural($value); } /** * @psalm-pure * - * @param mixed $value - * * - * @psalm-suppress MixedInferredReturnType https://github.com/vimeo/psalm/issues/5052 - * @psalm-suppress MixedReturnStatement https://github.com/vimeo/psalm/issues/5052 + * @return iterable */ function allNullOrNatural(mixed $value): iterable { - Assert::allNullOrNatural($value); - - return $value; + return Assert::allNullOrNatural($value); } diff --git a/tests/static-analysis/assert-negativeInteger.php b/tests/static-analysis/assert-negativeInteger.php index dc1ab5c0..9aa8a923 100644 --- a/tests/static-analysis/assert-negativeInteger.php +++ b/tests/static-analysis/assert-negativeInteger.php @@ -9,55 +9,39 @@ /** * @psalm-pure * - * @param mixed $value - * * @psalm-return negative-int */ function negativeInteger(mixed $value): int { - Assert::negativeInteger($value); - - return $value; + return Assert::negativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @psalm-return negative-int|null */ function nullOrNegativeInteger(mixed $value): ?int { - Assert::nullOrNegativeInteger($value); - - return $value; + return Assert::nullOrNegativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @return iterable */ function allNegativeInteger(mixed $value): iterable { - Assert::allNegativeInteger($value); - - return $value; + return Assert::allNegativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @return iterable */ function allNullOrNegativeInteger(mixed $value): iterable { - Assert::allNullOrNegativeInteger($value); - - return $value; + return Assert::allNullOrNegativeInteger($value); } diff --git a/tests/static-analysis/assert-notContains.php b/tests/static-analysis/assert-notContains.php index 1f6af8e7..ff9afa0d 100644 --- a/tests/static-analysis/assert-notContains.php +++ b/tests/static-analysis/assert-notContains.php @@ -11,9 +11,7 @@ */ function notContains(string $value, string $subString): string { - Assert::notContains($value, $subString); - - return $value; + return Assert::notContains($value, $subString); } /** @@ -21,9 +19,7 @@ function notContains(string $value, string $subString): string */ function nullOrNotContains(?string $value, string $subString): ?string { - Assert::nullOrNotContains($value, $subString); - - return $value; + return Assert::nullOrNotContains($value, $subString); } /** @@ -33,9 +29,7 @@ function nullOrNotContains(?string $value, string $subString): ?string */ function allNotContains(iterable $value, string $subString): iterable { - Assert::allNotContains($value, $subString); - - return $value; + return Assert::allNotContains($value, $subString); } /** @@ -45,7 +39,5 @@ function allNotContains(iterable $value, string $subString): iterable */ function allNullOrNotContains(iterable $value, string $subString): iterable { - Assert::allNullOrNotContains($value, $subString); - - return $value; + return Assert::allNullOrNotContains($value, $subString); } diff --git a/tests/static-analysis/assert-notEmpty.php b/tests/static-analysis/assert-notEmpty.php index 60a1fa3d..0cc52af9 100644 --- a/tests/static-analysis/assert-notEmpty.php +++ b/tests/static-analysis/assert-notEmpty.php @@ -11,9 +11,7 @@ */ function notEmptyNullableObject(?object $value): object { - Assert::notEmpty($value); - - return $value; + return Assert::notEmpty($value); } /** @@ -23,9 +21,7 @@ function notEmptyNullableObject(?object $value): object */ function notEmptyString(string $value) { - Assert::notEmpty($value); - - return $value; + return Assert::notEmpty($value); } /** @@ -35,9 +31,7 @@ function notEmptyString(string $value) */ function notEmptyBool(bool $value) { - Assert::notEmpty($value); - - return $value; + return Assert::notEmpty($value); } /** @@ -47,43 +41,29 @@ function notEmptyBool(bool $value) */ function notEmptyArray(array $value) { - Assert::notEmpty($value); - - return $value; + return Assert::notEmpty($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrNotEmpty(mixed $value): mixed { - Assert::nullOrNotEmpty($value); - - return $value; + return Assert::nullOrNotEmpty($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNotEmpty(mixed $value): mixed { - Assert::allNotEmpty($value); - - return $value; + return Assert::allNotEmpty($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrNotEmpty(mixed $value): mixed { - Assert::allNullOrNotEmpty($value); - - return $value; + return Assert::allNullOrNotEmpty($value); } diff --git a/tests/static-analysis/assert-notEndsWith.php b/tests/static-analysis/assert-notEndsWith.php new file mode 100644 index 00000000..5cbeead4 --- /dev/null +++ b/tests/static-analysis/assert-notEndsWith.php @@ -0,0 +1,43 @@ + $value + */ +function allNotEndsWith(iterable $value, string $suffix): iterable +{ + return Assert::allNotEndsWith($value, $suffix); +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotEndsWith(iterable $value, string $suffix): iterable +{ + return Assert::allNullOrNotEndsWith($value, $suffix); +} diff --git a/tests/static-analysis/assert-notEq.php b/tests/static-analysis/assert-notEq.php index 2e52b7d0..e7b58dce 100644 --- a/tests/static-analysis/assert-notEq.php +++ b/tests/static-analysis/assert-notEq.php @@ -6,46 +6,22 @@ use Webmozart\Assert\Assert; -/** - * @param mixed $value - * @param mixed $expect - */ -function notEq($value, $expect): mixed +function notEq(mixed $value, mixed $expect): mixed { - Assert::notEq($value, $expect); - - return $value; + return Assert::notEq($value, $expect); } -/** - * @param mixed $value - * @param mixed $expect - */ -function nullOrNotEq($value, $expect): mixed +function nullOrNotEq(mixed $value, mixed $expect): mixed { - Assert::nullOrNotEq($value, $expect); - - return $value; + return Assert::nullOrNotEq($value, $expect); } -/** - * @param mixed $value - * @param mixed $expect - */ -function allNotEq($value, $expect): mixed +function allNotEq(mixed $value, mixed $expect): mixed { - Assert::allNotEq($value, $expect); - - return $value; + return Assert::allNotEq($value, $expect); } -/** - * @param mixed $value - * @param mixed $expect - */ -function allNullOrNotEq($value, $expect): mixed +function allNullOrNotEq(mixed $value, mixed $expect): mixed { - Assert::allNullOrNotEq($value, $expect); - - return $value; + return Assert::allNullOrNotEq($value, $expect); } diff --git a/tests/static-analysis/assert-notFalse.php b/tests/static-analysis/assert-notFalse.php index 9de59ac6..fbfc5162 100644 --- a/tests/static-analysis/assert-notFalse.php +++ b/tests/static-analysis/assert-notFalse.php @@ -13,9 +13,7 @@ */ function notFalseBool(bool $value): bool { - Assert::notFalse($value); - - return $value; + return Assert::notFalse($value); } /** @@ -25,43 +23,33 @@ function notFalseBool(bool $value): bool */ function notFalseUnion(mixed $value): string { - Assert::notFalse($value); - - return $value; + return Assert::notFalse($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrNotFalse(mixed $value): mixed { - Assert::nullOrNotFalse($value); - - return $value; + return Assert::nullOrNotFalse($value); } /** * @psalm-pure * - * @param mixed $value + * @param iterable $value */ -function allNotFalse(mixed $value): mixed +function allNotFalse(iterable $value): iterable { - Assert::allNotFalse($value); - - return $value; + return Assert::allNotFalse($value); } /** * @psalm-pure * - * @param mixed $value + * @param iterable $value */ -function allNullOrNotFalse(mixed $value): mixed +function allNullOrNotFalse(iterable $value): iterable { - Assert::allNullOrNotFalse($value); - - return $value; + return Assert::allNullOrNotFalse($value); } diff --git a/tests/static-analysis/assert-notInArray.php b/tests/static-analysis/assert-notInArray.php index b59f4635..a77b17f7 100644 --- a/tests/static-analysis/assert-notInArray.php +++ b/tests/static-analysis/assert-notInArray.php @@ -9,9 +9,7 @@ */ function notInArray(mixed $value, array $values): mixed { - Assert::notInArray($value, $values); - - return $value; + return Assert::notInArray($value, $values); } /** @@ -19,9 +17,7 @@ function notInArray(mixed $value, array $values): mixed */ function nullOrNotInArray(mixed $value, array $values): mixed { - Assert::nullOrNotInArray($value, $values); - - return $value; + return Assert::nullOrNotInArray($value, $values); } /** @@ -29,7 +25,5 @@ function nullOrNotInArray(mixed $value, array $values): mixed */ function allNotInArray(mixed $value, array $values): mixed { - Assert::allNotInArray($value, $values); - - return $value; + return Assert::allNotInArray($value, $values); } diff --git a/tests/static-analysis/assert-notInstanceOf.php b/tests/static-analysis/assert-notInstanceOf.php index 7f627256..f341b521 100644 --- a/tests/static-analysis/assert-notInstanceOf.php +++ b/tests/static-analysis/assert-notInstanceOf.php @@ -4,55 +4,40 @@ namespace Webmozart\Assert\Tests\StaticAnalysis; -use DateTime; use stdClass; use Webmozart\Assert\Assert; /** - * @param stdClass|DateTime $value + * */ -function notInstanceOf(mixed $value): DateTime +function notInstanceOf(mixed $value): object { - Assert::notInstanceOf($value, stdClass::class); - - return $value; + return Assert::notInstanceOf($value, stdClass::class); } /** * @psalm-template T of object - * - * @param mixed $value * @param class-string $class */ -function nullOrNotInstanceOf($value, $class): mixed +function nullOrNotInstanceOf(mixed $value, $class): mixed { - Assert::nullOrNotInstanceOf($value, $class); - - return $value; + return Assert::nullOrNotInstanceOf($value, $class); } /** * @psalm-template T of object - * - * @param mixed $value * @param class-string $class */ -function allNotInstanceOf($value, $class): mixed +function allNotInstanceOf(mixed $value, $class): mixed { - Assert::allNotInstanceOf($value, $class); - - return $value; + return Assert::allNotInstanceOf($value, $class); } /** * @psalm-template T of object - * - * @param mixed $value * @param class-string $class */ -function allNullOrNotInstanceOf($value, $class): mixed +function allNullOrNotInstanceOf(mixed $value, $class): mixed { - Assert::allNullOrNotInstanceOf($value, $class); - - return $value; + return Assert::allNullOrNotInstanceOf($value, $class); } diff --git a/tests/static-analysis/assert-notNegativeInteger.php b/tests/static-analysis/assert-notNegativeInteger.php index 01874bd0..188f0a6c 100644 --- a/tests/static-analysis/assert-notNegativeInteger.php +++ b/tests/static-analysis/assert-notNegativeInteger.php @@ -9,57 +9,39 @@ /** * @psalm-pure * - * @param mixed $value - * * @psalm-return non-negative-int */ function nonNegativeInteger(mixed $value): int { - Assert::notNegativeInteger($value); - - $value *= -1; - - return $value; + return Assert::notNegativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @psalm-return non-negative-int|null */ function nullOrNonNegativeInteger(mixed $value): ?int { - Assert::nullOrNotNegativeInteger($value); - - return $value; + return Assert::nullOrNotNegativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @return iterable */ function allNonNegativeInteger(mixed $value): iterable { - Assert::allNotNegativeInteger($value); - - return $value; + return Assert::allNotNegativeInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @return iterable */ function allNullOrNonNegativeInteger(mixed $value): iterable { - Assert::allNullOrPositiveInteger($value); - - return $value; + return Assert::allNullOrPositiveInteger($value); } diff --git a/tests/static-analysis/assert-notNull.php b/tests/static-analysis/assert-notNull.php index ff4914c2..54736cad 100644 --- a/tests/static-analysis/assert-notNull.php +++ b/tests/static-analysis/assert-notNull.php @@ -11,19 +11,15 @@ */ function notNull(?object $value): object { - Assert::notNull($value); - - return $value; + return Assert::notNull($value); } /** * @psalm-pure * - * @param mixed $value + * @param iterable $value */ -function allNotNull(mixed $value): mixed +function allNotNull(iterable $value): iterable { - Assert::allNotNull($value); - - return $value; + return Assert::allNotNull($value); } diff --git a/tests/static-analysis/assert-notOneOf.php b/tests/static-analysis/assert-notOneOf.php index c7098d1e..726789e1 100644 --- a/tests/static-analysis/assert-notOneOf.php +++ b/tests/static-analysis/assert-notOneOf.php @@ -9,9 +9,7 @@ */ function notOneOf(mixed $value, array $values): mixed { - Assert::notOneOf($value, $values); - - return $value; + return Assert::notOneOf($value, $values); } /** @@ -19,9 +17,7 @@ function notOneOf(mixed $value, array $values): mixed */ function nullOrNotOneOf(mixed $value, array $values): mixed { - Assert::nullOrNotOneOf($value, $values); - - return $value; + return Assert::nullOrNotOneOf($value, $values); } /** @@ -29,7 +25,5 @@ function nullOrNotOneOf(mixed $value, array $values): mixed */ function allNotOneOf(mixed $value, array $values): mixed { - Assert::allNotOneOf($value, $values); - - return $value; + return Assert::allNotOneOf($value, $values); } diff --git a/tests/static-analysis/assert-notRegex.php b/tests/static-analysis/assert-notRegex.php index 531d9110..282214c3 100644 --- a/tests/static-analysis/assert-notRegex.php +++ b/tests/static-analysis/assert-notRegex.php @@ -11,9 +11,7 @@ */ function notRegex(string $value, string $pattern): string { - Assert::notRegex($value, $pattern); - - return $value; + return Assert::notRegex($value, $pattern); } /** @@ -21,9 +19,7 @@ function notRegex(string $value, string $pattern): string */ function nullOrNotRegex(?string $value, string $pattern): ?string { - Assert::nullOrNotRegex($value, $pattern); - - return $value; + return Assert::nullOrNotRegex($value, $pattern); } /** @@ -33,9 +29,7 @@ function nullOrNotRegex(?string $value, string $pattern): ?string */ function allNotRegex(iterable $value, string $pattern): iterable { - Assert::allNotRegex($value, $pattern); - - return $value; + return Assert::allNotRegex($value, $pattern); } /** @@ -45,7 +39,5 @@ function allNotRegex(iterable $value, string $pattern): iterable */ function allNullOrNotRegex(iterable $value, string $pattern): iterable { - Assert::allNotRegex($value, $pattern); - - return $value; + return Assert::allNotRegex($value, $pattern); } diff --git a/tests/static-analysis/assert-notSame.php b/tests/static-analysis/assert-notSame.php index 58ee3cf9..13b14af3 100644 --- a/tests/static-analysis/assert-notSame.php +++ b/tests/static-analysis/assert-notSame.php @@ -8,52 +8,36 @@ /** * @psalm-pure - * - * @param mixed $value * @param mixed $expect */ -function notSame($value, $expect): mixed +function notSame(mixed $value, $expect): mixed { - Assert::notSame($value, $expect); - - return $value; + return Assert::notSame($value, $expect); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $expect */ -function nullOrNotSame($value, $expect): mixed +function nullOrNotSame(mixed $value, $expect): mixed { - Assert::nullOrNotSame($value, $expect); - - return $value; + return Assert::nullOrNotSame($value, $expect); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $expect */ -function allNotSame($value, $expect): mixed +function allNotSame(mixed $value, $expect): mixed { - Assert::allNotSame($value, $expect); - - return $value; + return Assert::allNotSame($value, $expect); } /** * @psalm-pure - * - * @param mixed $value * @param mixed $expect */ -function allNullOrNotSame($value, $expect): mixed +function allNullOrNotSame(mixed $value, $expect): mixed { - Assert::allNullOrNotSame($value, $expect); - - return $value; + return Assert::allNullOrNotSame($value, $expect); } diff --git a/tests/static-analysis/assert-notStartsWith.php b/tests/static-analysis/assert-notStartsWith.php new file mode 100644 index 00000000..21944a64 --- /dev/null +++ b/tests/static-analysis/assert-notStartsWith.php @@ -0,0 +1,43 @@ + $value + */ +function allNotStartsWith(iterable $value, string $prefix): iterable +{ + return Assert::allNotStartsWith($value, $prefix); +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotStartsWith(iterable $value, string $prefix): iterable +{ + return Assert::allNullOrNotStartsWith($value, $prefix); +} diff --git a/tests/static-analysis/assert-notStatic.php b/tests/static-analysis/assert-notStatic.php index 0d08452b..17fcf0c7 100644 --- a/tests/static-analysis/assert-notStatic.php +++ b/tests/static-analysis/assert-notStatic.php @@ -2,13 +2,9 @@ namespace Webmozart\Assert\Tests\StaticAnalysis; -use Closure; use Webmozart\Assert\Assert; -/** - * @return Closure|callable-string - */ -function notStatic(mixed $closure): Closure|string +function notStatic(callable $closure): callable { return Assert::notStatic($closure); } diff --git a/tests/static-analysis/assert-notWhitespaceOnly.php b/tests/static-analysis/assert-notWhitespaceOnly.php index 3d8836c0..a296e0f3 100644 --- a/tests/static-analysis/assert-notWhitespaceOnly.php +++ b/tests/static-analysis/assert-notWhitespaceOnly.php @@ -11,9 +11,7 @@ */ function notWhitespaceOnly(string $value): string { - Assert::notWhitespaceOnly($value); - - return $value; + return Assert::notWhitespaceOnly($value); } /** @@ -21,9 +19,7 @@ function notWhitespaceOnly(string $value): string */ function nullOrNotWhitespaceOnly(?string $value): ?string { - Assert::nullOrNotWhitespaceOnly($value); - - return $value; + return Assert::nullOrNotWhitespaceOnly($value); } /** @@ -33,9 +29,7 @@ function nullOrNotWhitespaceOnly(?string $value): ?string */ function allNotWhitespaceOnly(iterable $value): iterable { - Assert::allNotWhitespaceOnly($value); - - return $value; + return Assert::allNotWhitespaceOnly($value); } /** @@ -45,7 +39,5 @@ function allNotWhitespaceOnly(iterable $value): iterable */ function allNullOrNotWhitespaceOnly(iterable $value): iterable { - Assert::allNullOrNotWhitespaceOnly($value); - - return $value; + return Assert::allNullOrNotWhitespaceOnly($value); } diff --git a/tests/static-analysis/assert-null.php b/tests/static-analysis/assert-null.php index 3aa6f9ab..6594f184 100644 --- a/tests/static-analysis/assert-null.php +++ b/tests/static-analysis/assert-null.php @@ -8,24 +8,16 @@ /** * @psalm-pure - * - * @param mixed $value */ function null(mixed $value): null { - Assert::null($value); - - return $value; + return Assert::null($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNull(mixed $value): iterable { - Assert::allNull($value); - - return $value; + return Assert::allNull($value); } diff --git a/tests/static-analysis/assert-numeric.php b/tests/static-analysis/assert-numeric.php index a91e96ed..2461ad51 100644 --- a/tests/static-analysis/assert-numeric.php +++ b/tests/static-analysis/assert-numeric.php @@ -9,51 +9,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return numeric */ function numeric(mixed $value) { - Assert::numeric($value); - - return $value; + return Assert::numeric($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|numeric */ function nullOrNumeric(mixed $value) { - Assert::nullOrNumeric($value); - - return $value; + return Assert::nullOrNumeric($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNumeric(mixed $value): iterable { - Assert::allNumeric($value); - - return $value; + return Assert::allNumeric($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrNumeric(mixed $value): iterable { - Assert::allNullOrNumeric($value); - - return $value; + return Assert::allNullOrNumeric($value); } diff --git a/tests/static-analysis/assert-object.php b/tests/static-analysis/assert-object.php index 82528073..6bd2af37 100644 --- a/tests/static-analysis/assert-object.php +++ b/tests/static-analysis/assert-object.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function object(mixed $value): object { - Assert::object($value); - - return $value; + return Assert::object($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrObject(mixed $value): ?object { - Assert::nullOrObject($value); - - return $value; + return Assert::nullOrObject($value); } /** * @psalm-pure - * - * @param mixed $value */ function allObject(mixed $value): iterable { - Assert::allObject($value); - - return $value; + return Assert::allObject($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrObject(mixed $value): iterable { - Assert::allNullOrObject($value); - - return $value; + return Assert::allNullOrObject($value); } diff --git a/tests/static-analysis/assert-objectish.php b/tests/static-analysis/assert-objectish.php index e22db6ac..3f8b62e6 100644 --- a/tests/static-analysis/assert-objectish.php +++ b/tests/static-analysis/assert-objectish.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function objectish(mixed $value): object|string { - Assert::objectish($value); - - return $value; + return Assert::objectish($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrObjectish(mixed $value): object|string|null { - Assert::nullOrObjectish($value); - - return $value; + return Assert::nullOrObjectish($value); } /** * @psalm-pure - * - * @param mixed $value */ function allObjectish(mixed $value): iterable { - Assert::allObjectish($value); - - return $value; + return Assert::allObjectish($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrObjectish(mixed $value): iterable { - Assert::allNullOrObjectish($value); - - return $value; + return Assert::allNullOrObjectish($value); } diff --git a/tests/static-analysis/assert-oneOf.php b/tests/static-analysis/assert-oneOf.php index 3a5e58ae..9e928be4 100644 --- a/tests/static-analysis/assert-oneOf.php +++ b/tests/static-analysis/assert-oneOf.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ -function oneOf($value, array $values): mixed +function oneOf(mixed $value, array $values): mixed { - Assert::oneOf($value, $values); - - return $value; + return Assert::oneOf($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function nullOrOneOf($value, array $values): mixed +function nullOrOneOf(mixed $value, array $values): mixed { - Assert::nullOrOneOf($value, $values); - - return $value; + return Assert::nullOrOneOf($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function allOneOf($value, array $values): mixed +function allOneOf(mixed $value, array $values): mixed { - Assert::allOneOf($value, $values); - - return $value; + return Assert::allOneOf($value, $values); } /** * @psalm-pure - * - * @param mixed $value */ -function allNullOrOneOf($value, array $values): mixed +function allNullOrOneOf(mixed $value, array $values): mixed { - Assert::allNullOrOneOf($value, $values); - - return $value; + return Assert::allNullOrOneOf($value, $values); } diff --git a/tests/static-analysis/assert-positiveInteger.php b/tests/static-analysis/assert-positiveInteger.php index 6425f089..2085be76 100644 --- a/tests/static-analysis/assert-positiveInteger.php +++ b/tests/static-analysis/assert-positiveInteger.php @@ -9,15 +9,11 @@ /** * @psalm-pure * - * @param mixed $value - * * @psalm-return positive-int */ function positiveInteger(mixed $value): int { - Assert::positiveInteger($value); - - return $value; + return Assert::positiveInteger($value); } /** @@ -29,45 +25,31 @@ function positiveInteger(mixed $value): int */ function positiveIntegerFiltersOutZero(mixed $value): int { - Assert::positiveInteger($value); - - return $value; + return Assert::positiveInteger($value); } /** * @psalm-pure * - * @param mixed $value - * * @psalm-return positive-int|null */ function nullOrPositiveInteger(mixed $value): ?int { - Assert::nullOrPositiveInteger($value); - - return $value; + return Assert::nullOrPositiveInteger($value); } /** * @psalm-pure - * - * @param mixed $value */ function allPositiveInteger(mixed $value): iterable { - Assert::allPositiveInteger($value); - - return $value; + return Assert::allPositiveInteger($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrPositiveInteger(mixed $value): iterable { - Assert::allPositiveInteger($value); - - return $value; + return Assert::allPositiveInteger($value); } diff --git a/tests/static-analysis/assert-propertyExists.php b/tests/static-analysis/assert-propertyExists.php index 0e52c9a1..0caa41d1 100644 --- a/tests/static-analysis/assert-propertyExists.php +++ b/tests/static-analysis/assert-propertyExists.php @@ -12,11 +12,9 @@ * @param class-string|object $classOrObject * @param mixed $property */ -function propertyExists($classOrObject, $property): string|object +function propertyExists(mixed $classOrObject, $property): string|object { - Assert::propertyExists($classOrObject, $property); - - return $classOrObject; + return Assert::propertyExists($classOrObject, $property); } /** @@ -25,11 +23,9 @@ function propertyExists($classOrObject, $property): string|object * @param null|class-string|object $classOrObject * @param mixed $property */ -function nullOrPropertyExists($classOrObject, $property): string|object|null +function nullOrPropertyExists(mixed $classOrObject, $property): string|object|null { - Assert::nullOrPropertyExists($classOrObject, $property); - - return $classOrObject; + return Assert::nullOrPropertyExists($classOrObject, $property); } /** @@ -40,9 +36,7 @@ function nullOrPropertyExists($classOrObject, $property): string|object|null */ function allPropertyExists(iterable $classOrObject, $property): iterable { - Assert::allPropertyExists($classOrObject, $property); - - return $classOrObject; + return Assert::allPropertyExists($classOrObject, $property); } /** @@ -53,7 +47,5 @@ function allPropertyExists(iterable $classOrObject, $property): iterable */ function allNullOrPropertyExists(iterable $classOrObject, $property): iterable { - Assert::allPropertyExists($classOrObject, $property); - - return $classOrObject; + return Assert::allNullOrPropertyExists($classOrObject, $property); } diff --git a/tests/static-analysis/assert-propertyNotExists.php b/tests/static-analysis/assert-propertyNotExists.php index 3ca6e45b..47cb76b8 100644 --- a/tests/static-analysis/assert-propertyNotExists.php +++ b/tests/static-analysis/assert-propertyNotExists.php @@ -12,11 +12,9 @@ * @param class-string|object $classOrObject * @param mixed $property */ -function propertyNotExists($classOrObject, $property): string|object +function propertyNotExists(mixed $classOrObject, $property): string|object { - Assert::propertyNotExists($classOrObject, $property); - - return $classOrObject; + return Assert::propertyNotExists($classOrObject, $property); } /** @@ -25,11 +23,9 @@ function propertyNotExists($classOrObject, $property): string|object * @param null|class-string|object $classOrObject * @param mixed $property */ -function nullOrPropertyNotExists($classOrObject, $property): string|object|null +function nullOrPropertyNotExists(mixed $classOrObject, $property): string|object|null { - Assert::nullOrPropertyNotExists($classOrObject, $property); - - return $classOrObject; + return Assert::nullOrPropertyNotExists($classOrObject, $property); } /** @@ -40,9 +36,7 @@ function nullOrPropertyNotExists($classOrObject, $property): string|object|null */ function allPropertyNotExists(iterable $classOrObject, $property): iterable { - Assert::allPropertyNotExists($classOrObject, $property); - - return $classOrObject; + return Assert::allPropertyNotExists($classOrObject, $property); } /** @@ -53,7 +47,5 @@ function allPropertyNotExists(iterable $classOrObject, $property): iterable */ function allNullOrPropertyNotExists(iterable $classOrObject, $property): iterable { - Assert::allNullOrPropertyNotExists($classOrObject, $property); - - return $classOrObject; + return Assert::allNullOrPropertyNotExists($classOrObject, $property); } diff --git a/tests/static-analysis/assert-psalm-notRedundant.php b/tests/static-analysis/assert-psalm-notRedundant.php index 344f7991..f232dde6 100644 --- a/tests/static-analysis/assert-psalm-notRedundant.php +++ b/tests/static-analysis/assert-psalm-notRedundant.php @@ -9,15 +9,11 @@ /** * @psalm-pure * - * @param mixed $value - * * @see https://github.com/webmozart/assert/pull/160#issuecomment-564491986 * @see https://github.com/vimeo/psalm/commit/4b715cdbffea19a7eab6f72482027d2dd358aab2 * @see https://github.com/vimeo/psalm/issues/2456 */ -function stringWillNotBeRedundantIfAssertingAndNotUsingEither(mixed $value): bool +function stringWillNotBeRedundantIfAssertingAndNotUsingEither(mixed $value): string { - Assert::string($value); - - return true; + return Assert::string($value); } diff --git a/tests/static-analysis/assert-psalm-plugin-return-type.php b/tests/static-analysis/assert-psalm-plugin-return-type.php new file mode 100644 index 00000000..01d533a8 --- /dev/null +++ b/tests/static-analysis/assert-psalm-plugin-return-type.php @@ -0,0 +1,27 @@ +|stdClass */ function subclassOf(mixed $value) { - Assert::subclassOf($value, stdClass::class); - - return $value; + return Assert::subclassOf($value, stdClass::class); } /** * @psalm-pure * - * @param mixed $value - * * @return null|class-string|stdClass */ function nullOrSubclassOf(mixed $value) { - Assert::nullOrSubclassOf($value, stdClass::class); - - return $value; + return Assert::nullOrSubclassOf($value, stdClass::class); } /** * @psalm-pure - * - * @param mixed $value */ function allSubclassOf(mixed $value): iterable { - Assert::allSubclassOf($value, stdClass::class); - - return $value; + return Assert::allSubclassOf($value, stdClass::class); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrSubclassOf(mixed $value): iterable { - Assert::allNullOrSubclassOf($value, stdClass::class); - - return $value; + return Assert::allNullOrSubclassOf($value, stdClass::class); } diff --git a/tests/static-analysis/assert-throws.php b/tests/static-analysis/assert-throws.php index 756e52a7..38383aea 100644 --- a/tests/static-analysis/assert-throws.php +++ b/tests/static-analysis/assert-throws.php @@ -13,9 +13,7 @@ */ function throws(Closure $value, $class): Closure { - Assert::throws($value, $class); - - return $value; + return Assert::throws($value, $class); } /** @@ -23,9 +21,7 @@ function throws(Closure $value, $class): Closure */ function nullOrThrows(?Closure $value, $class): ?Closure { - Assert::nullOrThrows($value, $class); - - return $value; + return Assert::nullOrThrows($value, $class); } /** @@ -34,9 +30,7 @@ function nullOrThrows(?Closure $value, $class): ?Closure */ function allThrows(iterable $value, $class): iterable { - Assert::allThrows($value, $class); - - return $value; + return Assert::allThrows($value, $class); } /** * @param iterable $value @@ -44,7 +38,5 @@ function allThrows(iterable $value, $class): iterable */ function allNullOrThrows(iterable $value, $class): iterable { - Assert::allNullOrThrows($value, $class); - - return $value; + return Assert::allNullOrThrows($value, $class); } diff --git a/tests/static-analysis/assert-true.php b/tests/static-analysis/assert-true.php index 80c1a4ee..306c6332 100644 --- a/tests/static-analysis/assert-true.php +++ b/tests/static-analysis/assert-true.php @@ -9,51 +9,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return true */ function true(mixed $value): bool { - Assert::true($value); - - return $value; + return Assert::true($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|true */ function nullOrTrue(mixed $value): ?bool { - Assert::nullOrTrue($value); - - return $value; + return Assert::nullOrTrue($value); } /** * @psalm-pure - * - * @param mixed $value */ function allTrue(mixed $value): iterable { - Assert::allTrue($value); - - return $value; + return Assert::allTrue($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrTrue(mixed $value): iterable { - Assert::allNullOrTrue($value); - - return $value; + return Assert::allNullOrTrue($value); } diff --git a/tests/static-analysis/assert-unicodeLetters.php b/tests/static-analysis/assert-unicodeLetters.php index e2d6d7c2..6c6801a5 100644 --- a/tests/static-analysis/assert-unicodeLetters.php +++ b/tests/static-analysis/assert-unicodeLetters.php @@ -8,48 +8,32 @@ /** * @psalm-pure - * - * @param mixed $value */ function unicodeLetters(mixed $value): mixed { - Assert::unicodeLetters($value); - - return $value; + return Assert::unicodeLetters($value); } /** * @psalm-pure - * - * @param mixed $value */ function nullOrUnicodeLetters(mixed $value): mixed { - Assert::nullOrUnicodeLetters($value); - - return $value; + return Assert::nullOrUnicodeLetters($value); } /** * @psalm-pure - * - * @param mixed $value */ function allUnicodeLetters(mixed $value): mixed { - Assert::allUnicodeLetters($value); - - return $value; + return Assert::allUnicodeLetters($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrUnicodeLetters(mixed $value): mixed { - Assert::allNullOrUnicodeLetters($value); - - return $value; + return Assert::allNullOrUnicodeLetters($value); } diff --git a/tests/static-analysis/assert-uniqueValues.php b/tests/static-analysis/assert-uniqueValues.php index 32446ab9..5e276bbf 100644 --- a/tests/static-analysis/assert-uniqueValues.php +++ b/tests/static-analysis/assert-uniqueValues.php @@ -6,36 +6,28 @@ use Webmozart\Assert\Assert; -function uniqueValues(array $values): array +function uniqueValues(mixed $values): array { - Assert::uniqueValues($values); - - return $values; + return Assert::uniqueValues($values); } -function nullOrUniqueValues(?array $values): ?array +function nullOrUniqueValues(mixed $values): ?array { - Assert::nullOrUniqueValues($values); - - return $values; + return Assert::nullOrUniqueValues($values); } /** - * @param iterable $values + * @return iterable */ function allUniqueValues(iterable $values): iterable { - Assert::allUniqueValues($values); - - return $values; + return Assert::allUniqueValues($values); } /** - * @param iterable $values + * @return iterable */ function allNullOrUniqueValues(iterable $values): iterable { - Assert::allNullOrUniqueValues($values); - - return $values; + return Assert::allNullOrUniqueValues($values); } diff --git a/tests/static-analysis/assert-upper.php b/tests/static-analysis/assert-upper.php index a4967309..fc4c4380 100644 --- a/tests/static-analysis/assert-upper.php +++ b/tests/static-analysis/assert-upper.php @@ -11,9 +11,7 @@ */ function upper(mixed $value): string { - Assert::upper($value); - - return $value; + return Assert::upper($value); } /** @@ -21,9 +19,7 @@ function upper(mixed $value): string */ function nullOrUpper(?string $value): ?string { - Assert::nullOrUpper($value); - - return $value; + return Assert::nullOrUpper($value); } /** @@ -33,9 +29,7 @@ function nullOrUpper(?string $value): ?string */ function allUpper(iterable $value): iterable { - Assert::allUpper($value); - - return $value; + return Assert::allUpper($value); } /** @@ -45,7 +39,5 @@ function allUpper(iterable $value): iterable */ function allNullOrUpper(iterable $value): iterable { - Assert::allNullOrUpper($value); - - return $value; + return Assert::allNullOrUpper($value); } diff --git a/tests/static-analysis/assert-uuid.php b/tests/static-analysis/assert-uuid.php index f2732361..004fd388 100644 --- a/tests/static-analysis/assert-uuid.php +++ b/tests/static-analysis/assert-uuid.php @@ -11,9 +11,7 @@ */ function uuid(string $value): string { - Assert::uuid($value); - - return $value; + return Assert::uuid($value); } /** @@ -21,9 +19,7 @@ function uuid(string $value): string */ function nullOrUuid(?string $value): ?string { - Assert::nullOrUuid($value); - - return $value; + return Assert::nullOrUuid($value); } /** @@ -33,9 +29,7 @@ function nullOrUuid(?string $value): ?string */ function allUuid(iterable $value): iterable { - Assert::allUuid($value); - - return $value; + return Assert::allUuid($value); } /** @@ -45,7 +39,5 @@ function allUuid(iterable $value): iterable */ function allNullOrUuid(iterable $value): iterable { - Assert::allNullOrUuid($value); - - return $value; + return Assert::allNullOrUuid($value); } diff --git a/tests/static-analysis/assert-validArrayKey.php b/tests/static-analysis/assert-validArrayKey.php index 8d0cf4d6..59e65802 100644 --- a/tests/static-analysis/assert-validArrayKey.php +++ b/tests/static-analysis/assert-validArrayKey.php @@ -9,51 +9,35 @@ /** * @psalm-pure * - * @param mixed $value - * * @return array-key */ function validArrayKey(mixed $value) { - Assert::validArrayKey($value); - - return $value; + return Assert::validArrayKey($value); } /** * @psalm-pure * - * @param mixed $value - * * @return null|array-key */ function nullOrValidArrayKey(mixed $value) { - Assert::nullOrValidArrayKey($value); - - return $value; + return Assert::nullOrValidArrayKey($value); } /** * @psalm-pure - * - * @param mixed $value */ function allValidArrayKey(mixed $value): iterable { - Assert::allValidArrayKey($value); - - return $value; + return Assert::allValidArrayKey($value); } /** * @psalm-pure - * - * @param mixed $value */ function allNullOrValidArrayKey(mixed $value): iterable { - Assert::allNullOrValidArrayKey($value); - - return $value; + return Assert::allNullOrValidArrayKey($value); } diff --git a/tests/static-analysis/assert-writable.php b/tests/static-analysis/assert-writable.php index 3f0476f0..80959eea 100644 --- a/tests/static-analysis/assert-writable.php +++ b/tests/static-analysis/assert-writable.php @@ -8,16 +8,12 @@ function writable(string $value): string { - Assert::writable($value); - - return $value; + return Assert::writable($value); } function nullOrWritable(?string $value): ?string { - Assert::nullOrWritable($value); - - return $value; + return Assert::nullOrWritable($value); } /** @@ -25,9 +21,7 @@ function nullOrWritable(?string $value): ?string */ function allWritable(iterable $value): iterable { - Assert::allWritable($value); - - return $value; + return Assert::allWritable($value); } /** @@ -35,7 +29,5 @@ function allWritable(iterable $value): iterable */ function allNullOrWritable(iterable $value): iterable { - Assert::allNullOrWritable($value); - - return $value; + return Assert::allNullOrWritable($value); } diff --git a/tests/static-analysis/non-return/assert-alnum.php b/tests/static-analysis/non-return/assert-alnum.php new file mode 100644 index 00000000..5f449812 --- /dev/null +++ b/tests/static-analysis/non-return/assert-alnum.php @@ -0,0 +1,51 @@ + $value + */ +function allAlnum(iterable $value): iterable +{ + Assert::allAlnum($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrAlnum(iterable $value): iterable +{ + Assert::allNullOrAlnum($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-alpha.php b/tests/static-analysis/non-return/assert-alpha.php new file mode 100644 index 00000000..5a416c37 --- /dev/null +++ b/tests/static-analysis/non-return/assert-alpha.php @@ -0,0 +1,47 @@ + $value + */ +function allContains(iterable $value, string $subString): iterable +{ + Assert::allContains($value, $subString); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrContains(iterable $value, string $subString): iterable +{ + Assert::allNullOrContains($value, $subString); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-count.php b/tests/static-analysis/non-return/assert-count.php new file mode 100644 index 00000000..eb412df4 --- /dev/null +++ b/tests/static-analysis/non-return/assert-count.php @@ -0,0 +1,48 @@ + $value + */ +function allCount(iterable $value, int $number): iterable +{ + Assert::allCount($value, $number); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrCount(iterable $value, int $number): iterable +{ + Assert::allCount($value, $number); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-countBetween.php b/tests/static-analysis/non-return/assert-countBetween.php new file mode 100644 index 00000000..65ba3b3e --- /dev/null +++ b/tests/static-analysis/non-return/assert-countBetween.php @@ -0,0 +1,56 @@ + $value + * @param int|float $min + * @param int|float $max + */ +function allCountBetween(iterable $value, $min, $max): iterable +{ + Assert::allCountBetween($value, $min, $max); + + return $value; +} + +/** + * @param iterable $value + * @param int|float $min + * @param int|float $max + */ +function allNullOrCountBetween(iterable $value, $min, $max): iterable +{ + Assert::allNullOrCountBetween($value, $min, $max); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-digits.php b/tests/static-analysis/non-return/assert-digits.php new file mode 100644 index 00000000..472ca41d --- /dev/null +++ b/tests/static-analysis/non-return/assert-digits.php @@ -0,0 +1,51 @@ + $value + */ +function allDigits(iterable $value): iterable +{ + Assert::allDigits($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrDigits(iterable $value): iterable +{ + Assert::allNullOrDigits($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-directory.php b/tests/static-analysis/non-return/assert-directory.php new file mode 100644 index 00000000..03b8a223 --- /dev/null +++ b/tests/static-analysis/non-return/assert-directory.php @@ -0,0 +1,47 @@ + $value + * @return iterable + */ +function allEmail(mixed $value): iterable +{ + Assert::allEmail($value); + + return $value; +} + +/** + * @param iterable $value + * @return iterable + */ +function allNullOrEmail(mixed $value): iterable +{ + Assert::allNullOrEmail($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-endsWith.php b/tests/static-analysis/non-return/assert-endsWith.php new file mode 100644 index 00000000..9b8c3416 --- /dev/null +++ b/tests/static-analysis/non-return/assert-endsWith.php @@ -0,0 +1,51 @@ + $value + */ +function allEndsWith(iterable $value, string $suffix): iterable +{ + Assert::allEndsWith($value, $suffix); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrEndsWith(iterable $value, string $suffix): iterable +{ + Assert::allNullOrEndsWith($value, $suffix); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-eq.php b/tests/static-analysis/non-return/assert-eq.php new file mode 100644 index 00000000..816305bc --- /dev/null +++ b/tests/static-analysis/non-return/assert-eq.php @@ -0,0 +1,51 @@ + + */ +function implementsInterface(mixed $value) +{ + Assert::implementsInterface($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + * + * @return Serializable|class-string|null + */ +function nullOrImplementsInterface(mixed $value) +{ + Assert::nullOrImplementsInterface($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + */ +function allImplementsInterface(mixed $value): iterable +{ + Assert::allImplementsInterface($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + */ +function allNullOrImplementsInterface(mixed $value): iterable +{ + Assert::allNullOrImplementsInterface($value, Serializable::class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-inArray.php b/tests/static-analysis/non-return/assert-inArray.php new file mode 100644 index 00000000..7cd152bb --- /dev/null +++ b/tests/static-analysis/non-return/assert-inArray.php @@ -0,0 +1,47 @@ + $value + */ +function allIp(iterable $value): iterable +{ + Assert::allIp($value); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrIp(iterable $value): iterable +{ + Assert::allNullOrIp($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-ipv4.php b/tests/static-analysis/non-return/assert-ipv4.php new file mode 100644 index 00000000..a0e16b80 --- /dev/null +++ b/tests/static-analysis/non-return/assert-ipv4.php @@ -0,0 +1,41 @@ + $value + */ +function allIpv4(iterable $value): iterable +{ + Assert::allIpv4($value); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrIpv4(iterable $value): iterable +{ + Assert::allNullOrIpv4($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-ipv6.php b/tests/static-analysis/non-return/assert-ipv6.php new file mode 100644 index 00000000..c1e9ee8b --- /dev/null +++ b/tests/static-analysis/non-return/assert-ipv6.php @@ -0,0 +1,41 @@ + $value + */ +function allIpv6(iterable $value): iterable +{ + Assert::allIpv6($value); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrIpv6(iterable $value): iterable +{ + Assert::allNullOrIpv6($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isAOf.php b/tests/static-analysis/non-return/assert-isAOf.php new file mode 100644 index 00000000..5adc7ea1 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isAOf.php @@ -0,0 +1,64 @@ +|Serializable + */ +function isAOf(mixed $value): mixed +{ + Assert::isAOf($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + * + * @param null|object|string $value + * + * @psalm-return null|class-string|Serializable + */ +function nullOrIsAOf(mixed $value): mixed +{ + Assert::nullOrIsAOf($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * + * @return iterable|Serializable> + */ +function allIsAOf(mixed $value): iterable +{ + Assert::allIsAOf($value, Serializable::class); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * + * @return iterable|Serializable|null> + */ +function allNullOrIsAOf(mixed $value): iterable +{ + Assert::allNullOrIsAOf($value, Serializable::class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isAnyOf.php b/tests/static-analysis/non-return/assert-isAnyOf.php new file mode 100644 index 00000000..7528522c --- /dev/null +++ b/tests/static-analysis/non-return/assert-isAnyOf.php @@ -0,0 +1,59 @@ + $classes + */ +function isAnyOf(mixed $value, array $classes): object|string +{ + Assert::isAnyOf($value, $classes); + + return $value; +} + +/** + * @psalm-pure + * + * @param null|object|string $value + * @param array $classes + */ +function nullOrIsAnyOf(mixed $value, array $classes): object|string|null +{ + Assert::nullOrIsAnyOf($value, $classes); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * @param array $classes + */ +function allIsAnyOf(mixed $value, array $classes): iterable +{ + Assert::allIsAnyOf($value, $classes); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * @param array $classes + */ +function allNullOrIsAnyOf(mixed $value, array $classes): iterable +{ + Assert::allNullOrIsAnyOf($value, $classes); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isArray.php b/tests/static-analysis/non-return/assert-isArray.php new file mode 100644 index 00000000..d494c2d7 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isArray.php @@ -0,0 +1,47 @@ + + */ +function allIsCountable(mixed $value) +{ + Assert::allIsCountable($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return iterable + */ +function allNullOrIsCountable(mixed $value) +{ + Assert::allNullOrIsCountable($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isEmpty.php b/tests/static-analysis/non-return/assert-isEmpty.php new file mode 100644 index 00000000..31712d38 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isEmpty.php @@ -0,0 +1,97 @@ + + */ +function isEmptyArray(array $value) +{ + Assert::isEmpty($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return null + */ +function nullOrIsEmpty(?object $value): null +{ + Assert::nullOrIsEmpty($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allIsEmpty(mixed $value): iterable +{ + Assert::allIsEmpty($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allNullOrIsEmpty(mixed $value): iterable +{ + Assert::allNullOrIsEmpty($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isInitialized.php b/tests/static-analysis/non-return/assert-isInitialized.php new file mode 100644 index 00000000..e7737e51 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isInitialized.php @@ -0,0 +1,17 @@ + $classes + */ +function isInstanceOfAny(object $value, array $classes): object +{ + Assert::isInstanceOfAny($value, $classes); + + return $value; +} + +/** + * @param object|null $value + * @param array $classes + */ +function nullOrIsInstanceOfAny(?object $value, array $classes): ?object +{ + Assert::nullOrIsInstanceOfAny($value, $classes); + + return $value; +} + +/** + * @param iterable $value + * @param array $classes + */ +function allIsInstanceOfAny(iterable $value, array $classes): iterable +{ + Assert::allIsInstanceOfAny($value, $classes); + + return $value; +} + +/** + * @param iterable $value + * @param array $classes + */ +function allNullOrIsInstanceOfAny(iterable $value, array $classes): iterable +{ + Assert::allNullOrIsInstanceOfAny($value, $classes); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isIterable.php b/tests/static-analysis/non-return/assert-isIterable.php new file mode 100644 index 00000000..2494e3b9 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isIterable.php @@ -0,0 +1,47 @@ + + */ +function isList(mixed $value): array +{ + Assert::isList($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param array $value + * + * @return list + */ +function isListWithKnownType(array $value): array +{ + Assert::isList($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return null|list + */ +function nullOrIsList(mixed $value): ?array +{ + Assert::nullOrIsList($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allIsList(mixed $value): iterable +{ + Assert::allIsList($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allNullOrIsList(mixed $value): iterable +{ + Assert::allNullOrIsList($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isMap.php b/tests/static-analysis/non-return/assert-isMap.php new file mode 100644 index 00000000..fb0b1c1b --- /dev/null +++ b/tests/static-analysis/non-return/assert-isMap.php @@ -0,0 +1,86 @@ + + */ +function isMap(mixed $value): array +{ + Assert::isMap($value); + + return $value; +} + +/** + * Verifying that the type of the elements in the array is preserved by the assertion + * + * @psalm-pure + * + * @param array $value + * + * @return array + */ +function isMapWithKnownType(array $value): array +{ + Assert::isMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return array + */ +function isMapWithEmptyArray(): array +{ + $value = []; + + Assert::isMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return null|array + */ +function nullOrIsMap(mixed $value): ?array +{ + Assert::nullOrIsMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable> $value + */ +function allIsMap(iterable $value): iterable +{ + Assert::allIsMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable> $value + */ +function allNullOrIsMap(iterable $value): iterable +{ + Assert::allNullOrIsMap($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isNonEmptyList.php b/tests/static-analysis/non-return/assert-isNonEmptyList.php new file mode 100644 index 00000000..fff6fb7a --- /dev/null +++ b/tests/static-analysis/non-return/assert-isNonEmptyList.php @@ -0,0 +1,63 @@ + + */ +function isNonEmptyList(mixed $value): array +{ + Assert::isNonEmptyList($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param array $value + */ +function isNonEmptyListWithRange(array $value): array +{ + Assert::isNonEmptyList($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return null|non-empty-list + */ +function nullOrIsNonEmptyList(mixed $value): ?array +{ + Assert::nullOrIsNonEmptyList($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allIsNonEmptyList(mixed $value): iterable +{ + Assert::allIsNonEmptyList($value); + + return $value; +} + +/** + * @psalm-pure + */ +function allNullOrIsNonEmptyList(mixed $value): iterable +{ + Assert::allNullOrIsNonEmptyList($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isNonEmptyMap.php b/tests/static-analysis/non-return/assert-isNonEmptyMap.php new file mode 100644 index 00000000..982171fa --- /dev/null +++ b/tests/static-analysis/non-return/assert-isNonEmptyMap.php @@ -0,0 +1,74 @@ + $value + * + * @return non-empty-array + */ +function isNonEmptyMap(array $value): array +{ + Assert::isNonEmptyMap($value); + + return $value; +} + +/** + * Verifying that the type of the elements in the array is preserved by the assertion + * + * @psalm-pure + * + * @param array $value + * + * @return non-empty-array + */ +function isNonEmptyMapWithKnownType(array $value): array +{ + Assert::isNonEmptyMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param array|null $value + */ +function nullOrIsNonEmptyMap(?array $value): ?array +{ + Assert::nullOrIsNonEmptyMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable> $value + */ +function allIsNonEmptyMap(iterable $value): iterable +{ + Assert::allIsNonEmptyMap($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable|null> $value + */ +function allNullOrIsNonEmptyMap(iterable $value): iterable +{ + Assert::allNullOrIsNonEmptyMap($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isNotA.php b/tests/static-analysis/non-return/assert-isNotA.php new file mode 100644 index 00000000..23c23f18 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isNotA.php @@ -0,0 +1,59 @@ + $value + * @param class-string $class + */ +function allIsNotA(mixed $value, $class): iterable +{ + Assert::allIsNotA($value, $class); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * @param class-string $class + */ +function allNullOrIsNotA(mixed $value, $class): iterable +{ + Assert::allNullOrIsNotA($value, $class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isNotInstanceOfAny.php b/tests/static-analysis/non-return/assert-isNotInstanceOfAny.php new file mode 100644 index 00000000..c77da872 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isNotInstanceOfAny.php @@ -0,0 +1,51 @@ + $classes + */ +function isNotInstanceOfAny(mixed $value, array $classes): mixed +{ + Assert::isNotInstanceOfAny($value, $classes); + + return $value; +} + +/** + * + * @param array $classes + */ +function nullOrIsNotInstanceOfAny(mixed $value, array $classes): mixed +{ + Assert::nullOrIsNotInstanceOfAny($value, $classes); + + return $value; +} + +/** + * @param iterable $value + * @param array $classes + */ +function allIsNotInstanceOfAny(iterable $value, array $classes): iterable +{ + Assert::allIsNotInstanceOfAny($value, $classes); + + return $value; +} + +/** + * @param iterable $value + * @param array $classes + */ +function allNullOrIsNotInstanceOfAny(iterable $value, array $classes): iterable +{ + Assert::allNullOrIsNotInstanceOfAny($value, $classes); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-isStatic.php b/tests/static-analysis/non-return/assert-isStatic.php new file mode 100644 index 00000000..b5cfe9f9 --- /dev/null +++ b/tests/static-analysis/non-return/assert-isStatic.php @@ -0,0 +1,12 @@ + $array + * @param array-key $key + */ +function allKeyExists(iterable $array, $key): iterable +{ + Assert::allKeyExists($array, $key); + + return $array; +} + +/** + * @psalm-pure + * + * @param iterable $array + * @param array-key $key + */ +function allNullOrKeyExists(iterable $array, $key): iterable +{ + Assert::allNullOrKeyExists($array, $key); + + return $array; +} diff --git a/tests/static-analysis/non-return/assert-keyNotExists.php b/tests/static-analysis/non-return/assert-keyNotExists.php new file mode 100644 index 00000000..d72fb13d --- /dev/null +++ b/tests/static-analysis/non-return/assert-keyNotExists.php @@ -0,0 +1,57 @@ + $array + * @param array-key $key + */ +function allKeyNotExists(iterable $array, $key): iterable +{ + Assert::allKeyNotExists($array, $key); + + return $array; +} + +/** + * @psalm-pure + * + * @param iterable $array + * @param array-key $key + */ +function allNullOrKeyNotExists(iterable $array, $key): iterable +{ + Assert::allNullOrKeyNotExists($array, $key); + + return $array; +} diff --git a/tests/static-analysis/non-return/assert-length.php b/tests/static-analysis/non-return/assert-length.php new file mode 100644 index 00000000..d5479d65 --- /dev/null +++ b/tests/static-analysis/non-return/assert-length.php @@ -0,0 +1,51 @@ + $value + */ +function allLength(iterable $value, int $length): iterable +{ + Assert::allLength($value, $length); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrLength(iterable $value, int $length): iterable +{ + Assert::allNullOrLength($value, $length); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-lengthBetween.php b/tests/static-analysis/non-return/assert-lengthBetween.php new file mode 100644 index 00000000..d0b6e79b --- /dev/null +++ b/tests/static-analysis/non-return/assert-lengthBetween.php @@ -0,0 +1,55 @@ + $value + * + * @return iterable + */ +function allLengthBetween(iterable $value, int $min, int $max): iterable +{ + Assert::allLengthBetween($value, $min, $max); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * + * @return iterable + */ +function allNullOrLengthBetween(iterable $value, int $min, int $max): iterable +{ + Assert::allNullOrLengthBetween($value, $min, $max); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-lessThan.php b/tests/static-analysis/non-return/assert-lessThan.php new file mode 100644 index 00000000..408504f5 --- /dev/null +++ b/tests/static-analysis/non-return/assert-lessThan.php @@ -0,0 +1,51 @@ + $value + */ +function allLower(iterable $value): iterable +{ + Assert::allLower($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrLower(iterable $value): iterable +{ + Assert::allNullOrLower($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-maxCount.php b/tests/static-analysis/non-return/assert-maxCount.php new file mode 100644 index 00000000..3fba3e3d --- /dev/null +++ b/tests/static-analysis/non-return/assert-maxCount.php @@ -0,0 +1,52 @@ + $array + * @param int|float $max + */ +function allMaxCount(iterable $array, $max): iterable +{ + Assert::allMaxCount($array, $max); + + return $array; +} + +/** + * @param iterable $array + * @param int|float $max + */ +function allNullOrMaxCount(iterable $array, $max): iterable +{ + Assert::allNullOrMaxCount($array, $max); + + return $array; +} diff --git a/tests/static-analysis/non-return/assert-maxLength.php b/tests/static-analysis/non-return/assert-maxLength.php new file mode 100644 index 00000000..0520c408 --- /dev/null +++ b/tests/static-analysis/non-return/assert-maxLength.php @@ -0,0 +1,55 @@ + $value + * + * @return iterable + */ +function allMaxLength(iterable $value, int $max): iterable +{ + Assert::allMaxLength($value, $max); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * + * @return iterable + */ +function allNullOrMaxLength(iterable $value, int $max): iterable +{ + Assert::allMaxLength($value, $max); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-methodExists.php b/tests/static-analysis/non-return/assert-methodExists.php new file mode 100644 index 00000000..ca3ca393 --- /dev/null +++ b/tests/static-analysis/non-return/assert-methodExists.php @@ -0,0 +1,59 @@ + $classOrObject + * @param mixed $method + */ +function allMethodExists(iterable $classOrObject, $method): iterable +{ + Assert::allMethodExists($classOrObject, $method); + + return $classOrObject; +} + +/** + * @psalm-pure + * + * @param iterable $classOrObject + * @param mixed $method + */ +function allNullOrMethodExists(iterable $classOrObject, $method): iterable +{ + Assert::allNullOrMethodExists($classOrObject, $method); + + return $classOrObject; +} diff --git a/tests/static-analysis/non-return/assert-methodNotExists.php b/tests/static-analysis/non-return/assert-methodNotExists.php new file mode 100644 index 00000000..a620b043 --- /dev/null +++ b/tests/static-analysis/non-return/assert-methodNotExists.php @@ -0,0 +1,59 @@ + $classOrObject + * @param mixed $method + */ +function allMethodNotExists(iterable $classOrObject, $method): iterable +{ + Assert::allMethodNotExists($classOrObject, $method); + + return $classOrObject; +} + +/** + * @psalm-pure + * + * @param iterable $classOrObject + * @param mixed $method + */ +function allNullOrMethodNotExists(iterable $classOrObject, $method): iterable +{ + Assert::allNullOrMethodNotExists($classOrObject, $method); + + return $classOrObject; +} diff --git a/tests/static-analysis/non-return/assert-minCount.php b/tests/static-analysis/non-return/assert-minCount.php new file mode 100644 index 00000000..8a0edc95 --- /dev/null +++ b/tests/static-analysis/non-return/assert-minCount.php @@ -0,0 +1,56 @@ + $array + * @param int|float $min + * + * @return iterable + */ +function allMinCount(mixed $array, $min) +{ + Assert::allMinCount($array, $min); + + return $array; +} + +/** + * @param iterable $array + * @param int|float $min + * + * @return iterable + */ +function allNullOrMinCount(mixed $array, $min) +{ + Assert::allNullOrMinCount($array, $min); + + return $array; +} diff --git a/tests/static-analysis/non-return/assert-minLength.php b/tests/static-analysis/non-return/assert-minLength.php new file mode 100644 index 00000000..5124d23d --- /dev/null +++ b/tests/static-analysis/non-return/assert-minLength.php @@ -0,0 +1,57 @@ + $value + * @param int|float $min + */ +function allMinLength(iterable $value, $min): iterable +{ + Assert::allMinLength($value, $min); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + * @param int|float $min + */ +function allNullOrMinLength(iterable $value, $min): iterable +{ + Assert::allNullOrMinLength($value, $min); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-natural.php b/tests/static-analysis/non-return/assert-natural.php new file mode 100644 index 00000000..fd211952 --- /dev/null +++ b/tests/static-analysis/non-return/assert-natural.php @@ -0,0 +1,55 @@ + + */ +function allNatural(mixed $value): iterable +{ + Assert::allNatural($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return iterable + */ +function allNullOrNatural(mixed $value): iterable +{ + Assert::allNullOrNatural($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-negativeInteger.php b/tests/static-analysis/non-return/assert-negativeInteger.php new file mode 100644 index 00000000..4943334d --- /dev/null +++ b/tests/static-analysis/non-return/assert-negativeInteger.php @@ -0,0 +1,55 @@ + + */ +function allNegativeInteger(mixed $value): iterable +{ + Assert::allNegativeInteger($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return iterable + */ +function allNullOrNegativeInteger(mixed $value): iterable +{ + Assert::allNullOrNegativeInteger($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notContains.php b/tests/static-analysis/non-return/assert-notContains.php new file mode 100644 index 00000000..1e48ff5b --- /dev/null +++ b/tests/static-analysis/non-return/assert-notContains.php @@ -0,0 +1,51 @@ + $value + */ +function allNotContains(iterable $value, string $subString): iterable +{ + Assert::allNotContains($value, $subString); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotContains(iterable $value, string $subString): iterable +{ + Assert::allNullOrNotContains($value, $subString); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notEmpty.php b/tests/static-analysis/non-return/assert-notEmpty.php new file mode 100644 index 00000000..89ae0f4f --- /dev/null +++ b/tests/static-analysis/non-return/assert-notEmpty.php @@ -0,0 +1,83 @@ + $value + */ +function allNotEndsWith(iterable $value, string $suffix): iterable +{ + Assert::allNotEndsWith($value, $suffix); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotEndsWith(iterable $value, string $suffix): iterable +{ + Assert::allNullOrNotEndsWith($value, $suffix); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notEq.php b/tests/static-analysis/non-return/assert-notEq.php new file mode 100644 index 00000000..59176f15 --- /dev/null +++ b/tests/static-analysis/non-return/assert-notEq.php @@ -0,0 +1,35 @@ + $value + */ +function allNotFalse(iterable $value): iterable +{ + Assert::allNotFalse($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotFalse(iterable $value): iterable +{ + Assert::allNullOrNotFalse($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notInArray.php b/tests/static-analysis/non-return/assert-notInArray.php new file mode 100644 index 00000000..21f3cab6 --- /dev/null +++ b/tests/static-analysis/non-return/assert-notInArray.php @@ -0,0 +1,35 @@ + $class + */ +function nullOrNotInstanceOf(mixed $value, $class): mixed +{ + Assert::nullOrNotInstanceOf($value, $class); + + return $value; +} + +/** + * @psalm-template T of object + * @param class-string $class + */ +function allNotInstanceOf(mixed $value, $class): mixed +{ + Assert::allNotInstanceOf($value, $class); + + return $value; +} + +/** + * @psalm-template T of object + * @param class-string $class + */ +function allNullOrNotInstanceOf(mixed $value, $class): mixed +{ + Assert::allNullOrNotInstanceOf($value, $class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notNegativeInteger.php b/tests/static-analysis/non-return/assert-notNegativeInteger.php new file mode 100644 index 00000000..71a853db --- /dev/null +++ b/tests/static-analysis/non-return/assert-notNegativeInteger.php @@ -0,0 +1,55 @@ + + */ +function allNonNegativeInteger(mixed $value): iterable +{ + Assert::allNotNegativeInteger($value); + + return $value; +} + +/** + * @psalm-pure + * + * @return iterable + */ +function allNullOrNonNegativeInteger(mixed $value): iterable +{ + Assert::allNullOrPositiveInteger($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notNull.php b/tests/static-analysis/non-return/assert-notNull.php new file mode 100644 index 00000000..6dac547e --- /dev/null +++ b/tests/static-analysis/non-return/assert-notNull.php @@ -0,0 +1,29 @@ + $value + */ +function allNotNull(iterable $value): iterable +{ + Assert::allNotNull($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notOneOf.php b/tests/static-analysis/non-return/assert-notOneOf.php new file mode 100644 index 00000000..a72f3f63 --- /dev/null +++ b/tests/static-analysis/non-return/assert-notOneOf.php @@ -0,0 +1,35 @@ + $value + */ +function allNotRegex(iterable $value, string $pattern): iterable +{ + Assert::allNotRegex($value, $pattern); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotRegex(iterable $value, string $pattern): iterable +{ + Assert::allNotRegex($value, $pattern); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notSame.php b/tests/static-analysis/non-return/assert-notSame.php new file mode 100644 index 00000000..2427cd06 --- /dev/null +++ b/tests/static-analysis/non-return/assert-notSame.php @@ -0,0 +1,51 @@ + $value + */ +function allNotStartsWith(iterable $value, string $prefix): iterable +{ + Assert::allNotStartsWith($value, $prefix); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotStartsWith(iterable $value, string $prefix): iterable +{ + Assert::allNullOrNotStartsWith($value, $prefix); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-notStatic.php b/tests/static-analysis/non-return/assert-notStatic.php new file mode 100644 index 00000000..c4196120 --- /dev/null +++ b/tests/static-analysis/non-return/assert-notStatic.php @@ -0,0 +1,12 @@ + $value + */ +function allNotWhitespaceOnly(iterable $value): iterable +{ + Assert::allNotWhitespaceOnly($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrNotWhitespaceOnly(iterable $value): iterable +{ + Assert::allNullOrNotWhitespaceOnly($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-null.php b/tests/static-analysis/non-return/assert-null.php new file mode 100644 index 00000000..8838b9bb --- /dev/null +++ b/tests/static-analysis/non-return/assert-null.php @@ -0,0 +1,27 @@ + $classOrObject + * @param mixed $property + */ +function allPropertyExists(iterable $classOrObject, $property): iterable +{ + Assert::allPropertyExists($classOrObject, $property); + + return $classOrObject; +} + +/** + * @psalm-pure + * + * @param iterable $classOrObject + * @param mixed $property + */ +function allNullOrPropertyExists(iterable $classOrObject, $property): iterable +{ + Assert::allNullOrPropertyExists($classOrObject, $property); + + return $classOrObject; +} diff --git a/tests/static-analysis/non-return/assert-propertyNotExists.php b/tests/static-analysis/non-return/assert-propertyNotExists.php new file mode 100644 index 00000000..a5a43414 --- /dev/null +++ b/tests/static-analysis/non-return/assert-propertyNotExists.php @@ -0,0 +1,59 @@ + $classOrObject + * @param mixed $property + */ +function allPropertyNotExists(iterable $classOrObject, $property): iterable +{ + Assert::allPropertyNotExists($classOrObject, $property); + + return $classOrObject; +} + +/** + * @psalm-pure + * + * @param iterable $classOrObject + * @param mixed $property + */ +function allNullOrPropertyNotExists(iterable $classOrObject, $property): iterable +{ + Assert::allNullOrPropertyNotExists($classOrObject, $property); + + return $classOrObject; +} diff --git a/tests/static-analysis/non-return/assert-psalm-notRedundant.php b/tests/static-analysis/non-return/assert-psalm-notRedundant.php new file mode 100644 index 00000000..2f142830 --- /dev/null +++ b/tests/static-analysis/non-return/assert-psalm-notRedundant.php @@ -0,0 +1,21 @@ + $value + * + * @return ArrayIterator + */ +function preserveContainerAllArrayIterator(mixed $value) +{ + Assert::allString($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-psalm-preserveStringType.php b/tests/static-analysis/non-return/assert-psalm-preserveStringType.php new file mode 100644 index 00000000..6dbe4713 --- /dev/null +++ b/tests/static-analysis/non-return/assert-psalm-preserveStringType.php @@ -0,0 +1,21 @@ + $value + */ +function allReadable(iterable $value): iterable +{ + Assert::allReadable($value); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrReadable(iterable $value): iterable +{ + Assert::allNullOrReadable($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-regex.php b/tests/static-analysis/non-return/assert-regex.php new file mode 100644 index 00000000..f76358df --- /dev/null +++ b/tests/static-analysis/non-return/assert-regex.php @@ -0,0 +1,51 @@ + $value + */ +function allRegex(iterable $value, string $pattern): iterable +{ + Assert::allRegex($value, $pattern); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrRegex(iterable $value, string $pattern): iterable +{ + Assert::allRegex($value, $pattern); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-resource.php b/tests/static-analysis/non-return/assert-resource.php new file mode 100644 index 00000000..4dda5d3d --- /dev/null +++ b/tests/static-analysis/non-return/assert-resource.php @@ -0,0 +1,51 @@ + $value + */ +function allStartsWith(iterable $value, string $prefix): iterable +{ + Assert::allStartsWith($value, $prefix); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrStartsWith(iterable $value, string $prefix): iterable +{ + Assert::allNullOrStartsWith($value, $prefix); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-startsWithLetter.php b/tests/static-analysis/non-return/assert-startsWithLetter.php new file mode 100644 index 00000000..19b027a5 --- /dev/null +++ b/tests/static-analysis/non-return/assert-startsWithLetter.php @@ -0,0 +1,47 @@ +|stdClass + */ +function subclassOf(mixed $value) +{ + Assert::subclassOf($value, stdClass::class); + + return $value; +} + +/** + * @psalm-pure + * + * @return null|class-string|stdClass + */ +function nullOrSubclassOf(mixed $value) +{ + Assert::nullOrSubclassOf($value, stdClass::class); + + return $value; +} + +/** + * @psalm-pure + */ +function allSubclassOf(mixed $value): iterable +{ + Assert::allSubclassOf($value, stdClass::class); + + return $value; +} + +/** + * @psalm-pure + */ +function allNullOrSubclassOf(mixed $value): iterable +{ + Assert::allNullOrSubclassOf($value, stdClass::class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-throws.php b/tests/static-analysis/non-return/assert-throws.php new file mode 100644 index 00000000..c9e5b6d5 --- /dev/null +++ b/tests/static-analysis/non-return/assert-throws.php @@ -0,0 +1,50 @@ + $class + */ +function throws(Closure $value, $class): Closure +{ + Assert::throws($value, $class); + + return $value; +} + +/** + * @param class-string $class + */ +function nullOrThrows(?Closure $value, $class): ?Closure +{ + Assert::nullOrThrows($value, $class); + + return $value; +} + +/** + * @param iterable $value + * @param class-string $class + */ +function allThrows(iterable $value, $class): iterable +{ + Assert::allThrows($value, $class); + + return $value; +} +/** + * @param iterable $value + * @param class-string $class + */ +function allNullOrThrows(iterable $value, $class): iterable +{ + Assert::allNullOrThrows($value, $class); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-true.php b/tests/static-analysis/non-return/assert-true.php new file mode 100644 index 00000000..54662aea --- /dev/null +++ b/tests/static-analysis/non-return/assert-true.php @@ -0,0 +1,51 @@ + + */ +function allUniqueValues(iterable $values): iterable +{ + Assert::allUniqueValues($values); + + return $values; +} + +/** + * @return iterable + */ +function allNullOrUniqueValues(iterable $values): iterable +{ + Assert::allNullOrUniqueValues($values); + + return $values; +} diff --git a/tests/static-analysis/non-return/assert-upper.php b/tests/static-analysis/non-return/assert-upper.php new file mode 100644 index 00000000..06d30896 --- /dev/null +++ b/tests/static-analysis/non-return/assert-upper.php @@ -0,0 +1,51 @@ + $value + */ +function allUpper(iterable $value): iterable +{ + Assert::allUpper($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrUpper(iterable $value): iterable +{ + Assert::allNullOrUpper($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-uuid.php b/tests/static-analysis/non-return/assert-uuid.php new file mode 100644 index 00000000..dcc426ff --- /dev/null +++ b/tests/static-analysis/non-return/assert-uuid.php @@ -0,0 +1,51 @@ + $value + */ +function allUuid(iterable $value): iterable +{ + Assert::allUuid($value); + + return $value; +} + +/** + * @psalm-pure + * + * @param iterable $value + */ +function allNullOrUuid(iterable $value): iterable +{ + Assert::allNullOrUuid($value); + + return $value; +} diff --git a/tests/static-analysis/non-return/assert-validArrayKey.php b/tests/static-analysis/non-return/assert-validArrayKey.php new file mode 100644 index 00000000..ed043a5d --- /dev/null +++ b/tests/static-analysis/non-return/assert-validArrayKey.php @@ -0,0 +1,51 @@ + $value + */ +function allWritable(iterable $value): iterable +{ + Assert::allWritable($value); + + return $value; +} + +/** + * @param iterable $value + */ +function allNullOrWritable(iterable $value): iterable +{ + Assert::allNullOrWritable($value); + + return $value; +}