Skip to content

Commit

Permalink
backport static analysis fixes to 1.7 (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz authored Aug 25, 2021
1 parent 0a2149e commit 821391f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Psl/Math/mean.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Return the arithmetic mean of the numbers in the given iterable.
*
* @param iterable<numeric> $numbers
* @param iterable<int|float> $numbers
*/
function mean(iterable $numbers): ?float
{
Expand All @@ -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;
}
6 changes: 3 additions & 3 deletions src/Psl/Math/sum_floats.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
/**
* Returns the float sum of the values of the given iterable.
*
* @param list<numeric> $numbers
* @param list<int|float> $numbers
*
* @pure
*/
function sum_floats(array $numbers): float
{
$result = 0.0;
foreach ($numbers as $number) {
$result += $number;
$result += (float)$number;
}

return (float) $result;
return $result;
}
1 change: 1 addition & 0 deletions src/Psl/Regex/every_match.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Regex/replace_with.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* `$callback`.
*
* @param non-empty-string $pattern The pattern to search for.
* @param (callable(array<int, string>): string) $callback The replacement callable.
* @param (callable(array<array-key, string>): string) $callback The replacement callable.
* @param null|positive-int $limit The maximum possible replacements for
* $pattern within $haystack.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Psl/Str/Byte/words.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
function words(string $string, ?string $characters_list = null): array
{
if (null === $characters_list) {
/** @var array<int, string> $words */
$words = str_word_count($string, 2);
} else {
/** @var array<int, string> $words */
$words = str_word_count($string, 2, $characters_list);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Type/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psl\Type\Exception\TypeTrace;

/**
* @template T
* @template-covariant T
*
* @implements TypeInterface<T>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Type/TypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Psl\Type\Exception\TypeTrace;

/**
* @template T
* @template-covariant T
*/
interface TypeInterface
{
Expand Down

0 comments on commit 821391f

Please sign in to comment.