Skip to content

Commit 6798cb7

Browse files
Add more nullsafe operators
1 parent 56ec28d commit 6798cb7

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

AbstractString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function wrap(array $values): array
7474

7575
foreach ($values as $k => $v) {
7676
if (\is_string($k) && '' !== $k && $k !== $j = (string) new static($k)) {
77-
$keys = $keys ?? array_keys($values);
77+
$keys ??= array_keys($values);
7878
$keys[$i] = $j;
7979
}
8080

ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function fromRandom(int $length = 16, string $alphabet = null): se
4848
throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length));
4949
}
5050

51-
$alphabet = $alphabet ?? self::ALPHABET_ALPHANUMERIC;
51+
$alphabet ??= self::ALPHABET_ALPHANUMERIC;
5252
$alphabetSize = \strlen($alphabet);
5353
$bits = (int) ceil(log($alphabetSize, 2.0));
5454
if ($bits <= 0 || $bits > 56) {
@@ -363,7 +363,7 @@ public function splice(string $replacement, int $start = 0, int $length = null):
363363

364364
public function split(string $delimiter, int $limit = null, int $flags = null): array
365365
{
366-
if (1 > $limit = $limit ?? \PHP_INT_MAX) {
366+
if (1 > $limit ??= \PHP_INT_MAX) {
367367
throw new InvalidArgumentException('Split limit must be a positive integer.');
368368
}
369369

CodePointString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function splice(string $replacement, int $start = 0, int $length = null):
210210

211211
public function split(string $delimiter, int $limit = null, int $flags = null): array
212212
{
213-
if (1 > $limit = $limit ?? \PHP_INT_MAX) {
213+
if (1 > $limit ??= \PHP_INT_MAX) {
214214
throw new InvalidArgumentException('Split limit must be a positive integer.');
215215
}
216216

Resources/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function b(?string $string = ''): ByteString
3131
*/
3232
function s(?string $string = ''): AbstractString
3333
{
34-
$string = $string ?? '';
34+
$string ??= '';
3535

3636
return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
3737
}

Slugger/AsciiSlugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getLocale(): string
9393
*/
9494
public function slug(string $string, string $separator = '-', string $locale = null): AbstractUnicodeString
9595
{
96-
$locale = $locale ?? $this->defaultLocale;
96+
$locale ??= $this->defaultLocale;
9797

9898
$transliterator = [];
9999
if ($locale && ('de' === $locale || str_starts_with($locale, 'de_'))) {

UnicodeString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function splice(string $replacement, int $start = 0, int $length = null):
280280

281281
public function split(string $delimiter, int $limit = null, int $flags = null): array
282282
{
283-
if (1 > $limit = $limit ?? 2147483647) {
283+
if (1 > $limit ??= 2147483647) {
284284
throw new InvalidArgumentException('Split limit must be a positive integer.');
285285
}
286286

0 commit comments

Comments
 (0)