mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-26 20:34:59 +01:00
migrate from Type\is_* to Type\*()->matches
This commit is contained in:
parent
9445a1e0e5
commit
57a8741d71
@ -24,7 +24,7 @@ function count_values(iterable $values): array
|
||||
|
||||
foreach ($values as $value) {
|
||||
Psl\invariant(
|
||||
Type\is_arraykey($value),
|
||||
Type\array_key()->matches($value),
|
||||
'Expected all values to be of type array-key, value of type (%s) provided.',
|
||||
gettype($value)
|
||||
);
|
||||
|
@ -29,7 +29,7 @@ function flip(iterable $iterable): array
|
||||
$result = [];
|
||||
foreach ($iterable as $key => $value) {
|
||||
Psl\invariant(
|
||||
Type\is_arraykey($value),
|
||||
Type\array_key()->matches($value),
|
||||
'Expected all values to be of type array-key, value of type (%s) provided.',
|
||||
gettype($value)
|
||||
);
|
||||
|
@ -48,7 +48,7 @@ function group_by(iterable $values, callable $key_func): array
|
||||
}
|
||||
|
||||
Psl\invariant(
|
||||
Type\is_arraykey($key),
|
||||
Type\array_key()->matches($key),
|
||||
'Expected $key_func to return a value of type array-key, value of type (%s) returned.',
|
||||
gettype($key)
|
||||
);
|
||||
|
@ -18,6 +18,9 @@ use function mb_internal_encoding;
|
||||
function internal_encoding(?string $encoding = null): string
|
||||
{
|
||||
Psl\invariant(null === $encoding || is_encoding_valid($encoding), 'Invalid encoding.');
|
||||
/** @psalm-suppress ImpureFunctionCall */
|
||||
return $encoding ?? (Type\is_string($internal_encoding = mb_internal_encoding()) ? $internal_encoding : 'UTF-8');
|
||||
/**
|
||||
* @psalm-suppress ImpureFunctionCall - see https://github.com/azjezz/psl/issues/130
|
||||
* @psalm-suppress ImpureMethodCall - see https://github.com/azjezz/psl/issues/130
|
||||
*/
|
||||
return $encoding ?? (Type\string()->matches($internal_encoding = mb_internal_encoding()) ? $internal_encoding : 'UTF-8');
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ function bytes(int $length): string
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (PHPException $e) {
|
||||
$code = $e->getCode();
|
||||
if (Type\is_string($code)) {
|
||||
if (Type\string()->matches($code)) {
|
||||
$code = Str\to_int($code) ?? 0;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ function int(int $min = Math\INT64_MIN, int $max = Math\INT64_MAX): int
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (PHPException $e) {
|
||||
$code = $e->getCode();
|
||||
if (Type\is_string($code)) {
|
||||
if (Type\string()->matches($code)) {
|
||||
$code = Str\to_int($code) ?? 0;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,10 @@ function split(string $string, string $delimiter, ?int $limit = null): array
|
||||
$result = explode($delimiter, $string, $limit);
|
||||
}
|
||||
|
||||
Psl\invariant(Type\is_array($result), 'Unexpected error');
|
||||
|
||||
return $result;
|
||||
/**
|
||||
* @psalm-suppress MissingThrowsDocblock - should not throw
|
||||
* @psalm-suppress ImpureFunctionCall - see https://github.com/azjezz/psl/issues/130
|
||||
* @psalm-suppress ImpureMethodCall - see https://github.com/azjezz/psl/issues/130
|
||||
*/
|
||||
return Type\vec(Type\string())->coerce($result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user