Utils::pregSplit: limit is not nullable

Correctly flagged by Psalm:
```
ERROR: PossiblyNullArgument - src\Utils.php:50:53 - Argument 3 of preg_split cannot be null, possibly null value provided (see https://psalm.dev/078)
        $parts = php_preg_split($pattern, $subject, $limit, $flags);
```

The `$limit` argument of the PHP native `preg_split()` function is not nullable.

Ref: https://www.php.net/manual/en/function.preg-split
This commit is contained in:
jrfnl
2021-08-08 21:32:50 +02:00
committed by Jaapio
parent 9ab603b069
commit 155efd647f
+2 -2
View File
@@ -29,7 +29,7 @@ abstract class Utils
* *
* @param string $pattern The pattern to search for, as a string. * @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string. * @param string $subject The input string.
* @param int|null $limit If specified, then only substrings up to limit are returned with the * @param int $limit If specified, then only substrings up to limit are returned with the
* rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit". * rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit".
* @param int $flags flags can be any combination of the following flags (combined with the | bitwise operator): * @param int $flags flags can be any combination of the following flags (combined with the | bitwise operator):
* *PREG_SPLIT_NO_EMPTY* * *PREG_SPLIT_NO_EMPTY*
@@ -46,7 +46,7 @@ abstract class Utils
* *
* @throws PcreException * @throws PcreException
*/ */
public static function pregSplit(string $pattern, string $subject, ?int $limit = -1, int $flags = 0): array public static function pregSplit(string $pattern, string $subject, int $limit = -1, int $flags = 0) : array
{ {
$parts = php_preg_split($pattern, $subject, $limit, $flags); $parts = php_preg_split($pattern, $subject, $limit, $flags);
if ($parts === false) { if ($parts === false) {