mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2025-01-22 05:11:47 +01:00
improve type coverage (#24)
This commit is contained in:
parent
e8dba9dc81
commit
f009542535
@ -1,6 +1,2 @@
|
|||||||
imports:
|
imports:
|
||||||
- php
|
- php
|
||||||
|
|
||||||
tools:
|
|
||||||
external_code_coverage:
|
|
||||||
timeout: 600 # Timeout in seconds.
|
|
||||||
|
@ -15,8 +15,6 @@ namespace Psl\Arr;
|
|||||||
* @psalm-return null|Tv
|
* @psalm-return null|Tv
|
||||||
*
|
*
|
||||||
* @psalm-pure
|
* @psalm-pure
|
||||||
*
|
|
||||||
* @psalm-suppress MissingReturnType
|
|
||||||
*/
|
*/
|
||||||
function first(array $array)
|
function first(array $array)
|
||||||
{
|
{
|
||||||
|
@ -17,8 +17,6 @@ use Psl\Random;
|
|||||||
* @psalm-param array<Tk, Tv> $values
|
* @psalm-param array<Tk, Tv> $values
|
||||||
*
|
*
|
||||||
* @psalm-return Tv
|
* @psalm-return Tv
|
||||||
*
|
|
||||||
* @psalm-suppress MissingReturnType
|
|
||||||
*/
|
*/
|
||||||
function random(array $values)
|
function random(array $values)
|
||||||
{
|
{
|
||||||
|
@ -27,8 +27,6 @@ use Psl\Iter;
|
|||||||
* @psalm-param list<iterable<Tk, Tv>> $iterables Iterables to combine
|
* @psalm-param list<iterable<Tk, Tv>> $iterables Iterables to combine
|
||||||
*
|
*
|
||||||
* @psalm-return iterable<list<Tk>, list<Tv>>
|
* @psalm-return iterable<list<Tk>, list<Tv>>
|
||||||
*
|
|
||||||
* @psalm-suppress MixedReturnTypeCoercion
|
|
||||||
*/
|
*/
|
||||||
function product(iterable ...$iterables): iterable
|
function product(iterable ...$iterables): iterable
|
||||||
{
|
{
|
||||||
|
@ -38,8 +38,10 @@ use Psl;
|
|||||||
* @psalm-pure
|
* @psalm-pure
|
||||||
*
|
*
|
||||||
* @see https://github.com/vimeo/psalm/issues/2152#issuecomment-533363310
|
* @see https://github.com/vimeo/psalm/issues/2152#issuecomment-533363310
|
||||||
* @psalm-suppress MixedOperand
|
|
||||||
* @psalm-suppress InvalidReturnType
|
* @psalm-suppress InvalidReturnType
|
||||||
|
* @psalm-suppress InvalidOperand
|
||||||
|
* @psalm-suppress RedundantConditionGivenDocblockType
|
||||||
|
* @psalm-suppress DocblockTypeContradiction
|
||||||
*/
|
*/
|
||||||
function range($start, $end, $step = null): Generator
|
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');
|
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) {
|
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;
|
yield $i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -65,8 +69,10 @@ function range($start, $end, $step = null): Generator
|
|||||||
Psl\invariant($step < 0, 'If start > end, the step must be negative');
|
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) {
|
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;
|
yield $i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,17 +20,19 @@ namespace Psl\Iter;
|
|||||||
* Iter\count(Iter\flatten([[1, 2, 3], [4], [5, 6], [7, 8]]))
|
* Iter\count(Iter\flatten([[1, 2, 3], [4], [5, 6], [7, 8]]))
|
||||||
* => Int(8)
|
* => Int(8)
|
||||||
*
|
*
|
||||||
* @psalm-param iterable $iterable
|
* @psalm-template T
|
||||||
|
*
|
||||||
|
* @psalm-param iterable<T> $iterable
|
||||||
*/
|
*/
|
||||||
function count(iterable $iterable): int
|
function count(iterable $iterable): int
|
||||||
{
|
{
|
||||||
if (\is_countable($iterable)) {
|
if (\is_countable($iterable)) {
|
||||||
/** @var array|\Countable $iterable */
|
/** @var array<array-key, T>|\Countable $iterable */
|
||||||
return \count($iterable);
|
return \count($iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
/** @psalm-var mixed $_ */
|
/** @psalm-var T $_ */
|
||||||
foreach ($iterable as $_) {
|
foreach ($iterable as $_) {
|
||||||
++$count;
|
++$count;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ use Psl;
|
|||||||
* @return int this function returns the Levenshtein-Distance between the
|
* @return int this function returns the Levenshtein-Distance between the
|
||||||
* two argument strings or -1, if one of the argument strings
|
* two argument strings or -1, if one of the argument strings
|
||||||
* is longer than the limit of 255 characters
|
* 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
|
function levenshtein(string $str1, string $str2, ?int $cost_of_insertion = null, ?int $cost_of_replacement = null, ?int $cost_of_deletion = null): int
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,6 @@ namespace Psl\Str;
|
|||||||
*
|
*
|
||||||
* If the optional character mask isn't provided, the following characters will
|
* If the optional character mask isn't provided, the following characters will
|
||||||
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
||||||
*
|
|
||||||
* @psalm-suppress NullArgument
|
|
||||||
*/
|
*/
|
||||||
function trim(string $string, ?string $char_mask = null): string
|
function trim(string $string, ?string $char_mask = null): string
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,6 @@ namespace Psl\Str;
|
|||||||
*
|
*
|
||||||
* If the optional character mask isn't provided, the following characters will
|
* If the optional character mask isn't provided, the following characters will
|
||||||
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
||||||
*
|
|
||||||
* @psalm-suppress NullArgument
|
|
||||||
*/
|
*/
|
||||||
function trim_left(string $string, ?string $char_mask = null): string
|
function trim_left(string $string, ?string $char_mask = null): string
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,6 @@ namespace Psl\Str;
|
|||||||
*
|
*
|
||||||
* If the optional character mask isn't provided, the following characters will
|
* If the optional character mask isn't provided, the following characters will
|
||||||
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
* be stripped: space, tab, newline, carriage return, NUL byte, vertical tab.
|
||||||
*
|
|
||||||
* @psalm-suppress NullArgument
|
|
||||||
*/
|
*/
|
||||||
function trim_right(string $string, ?string $char_mask = null): string
|
function trim_right(string $string, ?string $char_mask = null): string
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user