improve type coverage (#24)

This commit is contained in:
Saif Eddin G 2020-07-08 00:10:51 +02:00 committed by GitHub
parent e8dba9dc81
commit f009542535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 24 deletions

View File

@ -1,6 +1,2 @@
imports:
- php
tools:
external_code_coverage:
timeout: 600 # Timeout in seconds.

View File

@ -15,8 +15,6 @@ namespace Psl\Arr;
* @psalm-return null|Tv
*
* @psalm-pure
*
* @psalm-suppress MissingReturnType
*/
function first(array $array)
{

View File

@ -17,8 +17,6 @@ use Psl\Random;
* @psalm-param array<Tk, Tv> $values
*
* @psalm-return Tv
*
* @psalm-suppress MissingReturnType
*/
function random(array $values)
{

View File

@ -27,8 +27,6 @@ use Psl\Iter;
* @psalm-param list<iterable<Tk, Tv>> $iterables Iterables to combine
*
* @psalm-return iterable<list<Tk>, list<Tv>>
*
* @psalm-suppress MixedReturnTypeCoercion
*/
function product(iterable ...$iterables): iterable
{

View File

@ -38,8 +38,10 @@ use Psl;
* @psalm-pure
*
* @see https://github.com/vimeo/psalm/issues/2152#issuecomment-533363310
* @psalm-suppress MixedOperand
* @psalm-suppress InvalidReturnType
* @psalm-suppress InvalidOperand
* @psalm-suppress RedundantConditionGivenDocblockType
* @psalm-suppress DocblockTypeContradiction
*/
function range($start, $end, $step = null): Generator
{
@ -53,8 +55,10 @@ function range($start, $end, $step = null): Generator
Psl\invariant($step > 0, 'If start < end, the step must be positive');
}
/** @psalm-var T $i */
Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.');
for ($i = $start; $i <= $end; $i += $step) {
Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.');
Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.');
yield $i;
}
} else {
@ -65,8 +69,10 @@ function range($start, $end, $step = null): Generator
Psl\invariant($step < 0, 'If start > end, the step must be negative');
}
/** @psalm-var T $i */
Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.');
for ($i = $start; $i >= $end; $i += $step) {
Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.');
Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.');
yield $i;
}
}

View File

@ -20,17 +20,19 @@ namespace Psl\Iter;
* Iter\count(Iter\flatten([[1, 2, 3], [4], [5, 6], [7, 8]]))
* => Int(8)
*
* @psalm-param iterable $iterable
* @psalm-template T
*
* @psalm-param iterable<T> $iterable
*/
function count(iterable $iterable): int
{
if (\is_countable($iterable)) {
/** @var array|\Countable $iterable */
/** @var array<array-key, T>|\Countable $iterable */
return \count($iterable);
}
$count = 0;
/** @psalm-var mixed $_ */
/** @psalm-var T $_ */
foreach ($iterable as $_) {
++$count;
}

View File

@ -19,8 +19,6 @@ use Psl;
* @return int this function returns the Levenshtein-Distance between the
* two argument strings or -1, if one of the argument strings
* is longer than the limit of 255 characters
*
* @psalm-suppress PossiblyNullArgument
*/
function levenshtein(string $str1, string $str2, ?int $cost_of_insertion = null, ?int $cost_of_replacement = null, ?int $cost_of_deletion = null): int
{

View File

@ -9,8 +9,6 @@ namespace Psl\Str;
*
* If the optional character mask isn't provided, the following characters will
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
*
* @psalm-suppress NullArgument
*/
function trim(string $string, ?string $char_mask = null): string
{

View File

@ -9,8 +9,6 @@ namespace Psl\Str;
*
* If the optional character mask isn't provided, the following characters will
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
*
* @psalm-suppress NullArgument
*/
function trim_left(string $string, ?string $char_mask = null): string
{

View File

@ -9,8 +9,6 @@ namespace Psl\Str;
*
* If the optional character mask isn't provided, the following characters will
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
*
* @psalm-suppress NullArgument
*/
function trim_right(string $string, ?string $char_mask = null): string
{