From 821391fe0539b2158efff4c72916d18d829be9a0 Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati <29315886+azjezz@users.noreply.github.com> Date: Wed, 25 Aug 2021 02:38:18 +0100 Subject: [PATCH] backport static analysis fixes to 1.7 (#221) --- src/Psl/Math/mean.php | 6 +++--- src/Psl/Math/sum_floats.php | 6 +++--- src/Psl/Regex/every_match.php | 1 + src/Psl/Regex/replace_with.php | 2 +- src/Psl/Str/Byte/words.php | 2 -- src/Psl/Type/Type.php | 2 +- src/Psl/Type/TypeInterface.php | 2 +- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Psl/Math/mean.php b/src/Psl/Math/mean.php index 712bc481..7e9e2836 100644 --- a/src/Psl/Math/mean.php +++ b/src/Psl/Math/mean.php @@ -9,7 +9,7 @@ /** * Return the arithmetic mean of the numbers in the given iterable. * - * @param iterable $numbers + * @param iterable $numbers */ function mean(iterable $numbers): ?float { @@ -20,8 +20,8 @@ function mean(iterable $numbers): ?float $mean = 0.0; foreach ($numbers as $number) { - $mean += $number / $count; + $mean += (float)$number / $count; } - return (float) $mean; + return $mean; } diff --git a/src/Psl/Math/sum_floats.php b/src/Psl/Math/sum_floats.php index c72651a6..51fb4fa6 100644 --- a/src/Psl/Math/sum_floats.php +++ b/src/Psl/Math/sum_floats.php @@ -7,7 +7,7 @@ /** * Returns the float sum of the values of the given iterable. * - * @param list $numbers + * @param list $numbers * * @pure */ @@ -15,8 +15,8 @@ function sum_floats(array $numbers): float { $result = 0.0; foreach ($numbers as $number) { - $result += $number; + $result += (float)$number; } - return (float) $result; + return $result; } diff --git a/src/Psl/Regex/every_match.php b/src/Psl/Regex/every_match.php index 9c187f8e..c5fdbccb 100644 --- a/src/Psl/Regex/every_match.php +++ b/src/Psl/Regex/every_match.php @@ -45,6 +45,7 @@ static function () use ($subject, $pattern, $offset): ?array { $capture_groups ??= Type\dict(Type\array_key(), Type\string()); try { + /** @psalm-suppress InvalidArgument */ return Type\vec($capture_groups)->coerce($matching); } catch (InvariantViolationException | Type\Exception\CoercionException $e) { throw new Exception\RuntimeException('Invalid capture groups', 0, $e); diff --git a/src/Psl/Regex/replace_with.php b/src/Psl/Regex/replace_with.php index a73df7bd..89565a31 100644 --- a/src/Psl/Regex/replace_with.php +++ b/src/Psl/Regex/replace_with.php @@ -15,7 +15,7 @@ * `$callback`. * * @param non-empty-string $pattern The pattern to search for. - * @param (callable(array): string) $callback The replacement callable. + * @param (callable(array): string) $callback The replacement callable. * @param null|positive-int $limit The maximum possible replacements for * $pattern within $haystack. * diff --git a/src/Psl/Str/Byte/words.php b/src/Psl/Str/Byte/words.php index 5005b829..78eb280c 100644 --- a/src/Psl/Str/Byte/words.php +++ b/src/Psl/Str/Byte/words.php @@ -19,10 +19,8 @@ function words(string $string, ?string $characters_list = null): array { if (null === $characters_list) { - /** @var array $words */ $words = str_word_count($string, 2); } else { - /** @var array $words */ $words = str_word_count($string, 2, $characters_list); } diff --git a/src/Psl/Type/Type.php b/src/Psl/Type/Type.php index e56fee6e..9bc647f1 100644 --- a/src/Psl/Type/Type.php +++ b/src/Psl/Type/Type.php @@ -8,7 +8,7 @@ use Psl\Type\Exception\TypeTrace; /** - * @template T + * @template-covariant T * * @implements TypeInterface */ diff --git a/src/Psl/Type/TypeInterface.php b/src/Psl/Type/TypeInterface.php index 0633fa86..4c1831da 100644 --- a/src/Psl/Type/TypeInterface.php +++ b/src/Psl/Type/TypeInterface.php @@ -9,7 +9,7 @@ use Psl\Type\Exception\TypeTrace; /** - * @template T + * @template-covariant T */ interface TypeInterface {