diff --git a/AbstractString.php b/AbstractString.php index ed1417a..6b125d4 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -383,7 +383,7 @@ public function isEmpty(): bool return '' === $this->string; } - abstract public function join(array $strings, string $lastGlue = null): static; + abstract public function join(array $strings, ?string $lastGlue = null): static; public function jsonSerialize(): string { @@ -429,16 +429,16 @@ abstract public function replaceMatches(string $fromRegexp, string|callable $to) abstract public function reverse(): static; - abstract public function slice(int $start = 0, int $length = null): static; + abstract public function slice(int $start = 0, ?int $length = null): static; abstract public function snake(): static; - abstract public function splice(string $replacement, int $start = 0, int $length = null): static; + abstract public function splice(string $replacement, int $start = 0, ?int $length = null): static; /** * @return static[] */ - public function split(string $delimiter, int $limit = null, int $flags = null): array + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array { if (null === $flags) { throw new \TypeError('Split behavior when $flags is null must be implemented by child classes.'); @@ -495,7 +495,7 @@ public function startsWith(string|iterable $prefix): bool abstract public function title(bool $allWords = false): static; - public function toByteString(string $toEncoding = null): ByteString + public function toByteString(?string $toEncoding = null): ByteString { $b = new ByteString(); diff --git a/AbstractUnicodeString.php b/AbstractUnicodeString.php index d19a61a..74c47a0 100644 --- a/AbstractUnicodeString.php +++ b/AbstractUnicodeString.php @@ -198,7 +198,7 @@ public function folded(bool $compat = true): static return $str; } - public function join(array $strings, string $lastGlue = null): static + public function join(array $strings, ?string $lastGlue = null): static { $str = clone $this; diff --git a/ByteString.php b/ByteString.php index 212290f..8ef3981 100644 --- a/ByteString.php +++ b/ByteString.php @@ -42,7 +42,7 @@ public function __construct(string $string = '') * Copyright (c) 2004-2020, Facebook, Inc. (https://www.facebook.com/) */ - public static function fromRandom(int $length = 16, string $alphabet = null): self + public static function fromRandom(int $length = 16, ?string $alphabet = null): self { if ($length <= 0) { throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length)); @@ -205,7 +205,7 @@ public function isUtf8(): bool return '' === $this->string || preg_match('//u', $this->string); } - public function join(array $strings, string $lastGlue = null): static + public function join(array $strings, ?string $lastGlue = null): static { $str = clone $this; @@ -332,7 +332,7 @@ public function reverse(): static return $str; } - public function slice(int $start = 0, int $length = null): static + public function slice(int $start = 0, ?int $length = null): static { $str = clone $this; $str->string = (string) substr($this->string, $start, $length ?? \PHP_INT_MAX); @@ -348,7 +348,7 @@ public function snake(): static return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): static + public function splice(string $replacement, int $start = 0, ?int $length = null): static { $str = clone $this; $str->string = substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX); @@ -356,7 +356,7 @@ public function splice(string $replacement, int $start = 0, int $length = null): return $str; } - public function split(string $delimiter, int $limit = null, int $flags = null): array + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array { if (1 > $limit ??= \PHP_INT_MAX) { throw new InvalidArgumentException('Split limit must be a positive integer.'); @@ -402,12 +402,12 @@ public function title(bool $allWords = false): static return $str; } - public function toUnicodeString(string $fromEncoding = null): UnicodeString + public function toUnicodeString(?string $fromEncoding = null): UnicodeString { return new UnicodeString($this->toCodePointString($fromEncoding)->string); } - public function toCodePointString(string $fromEncoding = null): CodePointString + public function toCodePointString(?string $fromEncoding = null): CodePointString { $u = new CodePointString(); diff --git a/CodePointString.php b/CodePointString.php index f5c900f..337bfc1 100644 --- a/CodePointString.php +++ b/CodePointString.php @@ -186,7 +186,7 @@ public function replace(string $from, string $to): static return $str; } - public function slice(int $start = 0, int $length = null): static + public function slice(int $start = 0, ?int $length = null): static { $str = clone $this; $str->string = mb_substr($this->string, $start, $length, 'UTF-8'); @@ -194,7 +194,7 @@ public function slice(int $start = 0, int $length = null): static return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): static + public function splice(string $replacement, int $start = 0, ?int $length = null): static { if (!preg_match('//u', $replacement)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); @@ -208,7 +208,7 @@ public function splice(string $replacement, int $start = 0, int $length = null): return $str; } - public function split(string $delimiter, int $limit = null, int $flags = null): array + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array { if (1 > $limit ??= \PHP_INT_MAX) { throw new InvalidArgumentException('Split limit must be a positive integer.'); diff --git a/Slugger/AsciiSlugger.php b/Slugger/AsciiSlugger.php index 6e550c6..a9693d4 100644 --- a/Slugger/AsciiSlugger.php +++ b/Slugger/AsciiSlugger.php @@ -68,7 +68,7 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface */ private array $transliterators = []; - public function __construct(string $defaultLocale = null, array|\Closure $symbolsMap = null) + public function __construct(?string $defaultLocale = null, array|\Closure|null $symbolsMap = null) { $this->defaultLocale = $defaultLocale; $this->symbolsMap = $symbolsMap ?? $this->symbolsMap; @@ -104,7 +104,7 @@ public function withEmoji(bool|string $emoji = true): static return $new; } - public function slug(string $string, string $separator = '-', string $locale = null): AbstractUnicodeString + public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString { $locale ??= $this->defaultLocale; diff --git a/Slugger/SluggerInterface.php b/Slugger/SluggerInterface.php index c679ed9..dd0d581 100644 --- a/Slugger/SluggerInterface.php +++ b/Slugger/SluggerInterface.php @@ -23,5 +23,5 @@ interface SluggerInterface /** * Creates a slug for the given string and locale, using appropriate transliteration when needed. */ - public function slug(string $string, string $separator = '-', string $locale = null): AbstractUnicodeString; + public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString; } diff --git a/Tests/AbstractAsciiTestCase.php b/Tests/AbstractAsciiTestCase.php index b4578c7..eabe7b9 100644 --- a/Tests/AbstractAsciiTestCase.php +++ b/Tests/AbstractAsciiTestCase.php @@ -46,7 +46,7 @@ public function testCreateFromEmptyString() /** * @dataProvider provideBytesAt */ - public function testBytesAt(array $expected, string $string, int $offset, int $form = null) + public function testBytesAt(array $expected, string $string, int $offset, ?int $form = null) { if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) { $this->markTestSkipped('Skipping due to issue ICU-21661.'); @@ -319,7 +319,7 @@ public static function provideIndexOfLastIgnoreCase(): array /** * @dataProvider provideSplit */ - public function testSplit(string $string, string $delimiter, array $chunks, ?int $limit, int $flags = null) + public function testSplit(string $string, string $delimiter, array $chunks, ?int $limit, ?int $flags = null) { $this->assertEquals($chunks, static::createFromString($string)->split($delimiter, $limit, $flags)); } @@ -595,7 +595,7 @@ public static function provideTitle() /** * @dataProvider provideSlice */ - public function testSlice(string $expected, string $origin, int $start, int $length = null) + public function testSlice(string $expected, string $origin, int $start, ?int $length = null) { $this->assertEquals( static::createFromString($expected), @@ -623,7 +623,7 @@ public static function provideSlice() /** * @dataProvider provideSplice */ - public function testSplice(string $expected, int $start, int $length = null) + public function testSplice(string $expected, int $start, ?int $length = null) { $this->assertEquals( static::createFromString($expected), @@ -1081,7 +1081,7 @@ public static function provideSnake() /** * @dataProvider provideStartsWith */ - public function testStartsWith(bool $expected, string $origin, $prefix, int $form = null) + public function testStartsWith(bool $expected, string $origin, $prefix, ?int $form = null) { $instance = static::createFromString($origin); $instance = $form ? $instance->normalize($form) : $instance; @@ -1135,7 +1135,7 @@ public static function provideStartsWithIgnoreCase() /** * @dataProvider provideEndsWith */ - public function testEndsWith(bool $expected, string $origin, $suffix, int $form = null) + public function testEndsWith(bool $expected, string $origin, $suffix, ?int $form = null) { $instance = static::createFromString($origin); $instance = $form ? $instance->normalize($form) : $instance; diff --git a/Tests/AbstractUnicodeTestCase.php b/Tests/AbstractUnicodeTestCase.php index e95dddd..049d0b1 100644 --- a/Tests/AbstractUnicodeTestCase.php +++ b/Tests/AbstractUnicodeTestCase.php @@ -78,7 +78,7 @@ public static function provideBytesAt(): array /** * @dataProvider provideCodePointsAt */ - public function testCodePointsAt(array $expected, string $string, int $offset, int $form = null) + public function testCodePointsAt(array $expected, string $string, int $offset, ?int $form = null) { if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) { $this->markTestSkipped('Skipping due to issue ICU-21661.'); diff --git a/Tests/Slugger/AsciiSluggerTest.php b/Tests/Slugger/AsciiSluggerTest.php index 3544367..703212f 100644 --- a/Tests/Slugger/AsciiSluggerTest.php +++ b/Tests/Slugger/AsciiSluggerTest.php @@ -19,7 +19,7 @@ class AsciiSluggerTest extends TestCase /** * @dataProvider provideSlugTests */ - public function testSlug(string $expected, string $string, string $separator = '-', string $locale = null) + public function testSlug(string $expected, string $string, string $separator = '-', ?string $locale = null) { $slugger = new AsciiSlugger(); diff --git a/UnicodeString.php b/UnicodeString.php index a64c6a9..a10208b 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -176,7 +176,7 @@ public function indexOfLast(string|iterable|AbstractString $needle, int $offset return false === $i ? null : $i; } - public function join(array $strings, string $lastGlue = null): static + public function join(array $strings, ?string $lastGlue = null): static { $str = parent::join($strings, $lastGlue); normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); @@ -253,7 +253,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static return $str; } - public function slice(int $start = 0, int $length = null): static + public function slice(int $start = 0, ?int $length = null): static { $str = clone $this; @@ -262,7 +262,7 @@ public function slice(int $start = 0, int $length = null): static return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): static + public function splice(string $replacement, int $start = 0, ?int $length = null): static { $str = clone $this; @@ -278,7 +278,7 @@ public function splice(string $replacement, int $start = 0, int $length = null): return $str; } - public function split(string $delimiter, int $limit = null, int $flags = null): array + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array { if (1 > $limit ??= 2147483647) { throw new InvalidArgumentException('Split limit must be a positive integer.');