migrate from Type\is_* to Type\*()->matches

This commit is contained in:
azjezz 2021-02-17 20:19:06 +01:00 committed by Saif Eddin Gmati
parent 9445a1e0e5
commit 57a8741d71
7 changed files with 16 additions and 10 deletions

View File

@ -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)
);

View File

@ -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)
);

View File

@ -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)
);

View File

@ -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');
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}