From c209c4d0559acce1c9a2067612cfb5d35756edc2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 14:51:25 +0100 Subject: [PATCH] Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value --- AbstractString.php | 10 +++++----- AbstractUnicodeString.php | 2 +- ByteString.php | 14 +++++++------- CodePointString.php | 6 +++--- Slugger/AsciiSlugger.php | 4 ++-- Slugger/SluggerInterface.php | 2 +- Tests/AbstractAsciiTestCase.php | 12 ++++++------ Tests/AbstractUnicodeTestCase.php | 2 +- Tests/Slugger/AsciiSluggerTest.php | 2 +- UnicodeString.php | 8 ++++---- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/AbstractString.php b/AbstractString.php index a0a801e..d3240ca 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -399,7 +399,7 @@ public function isEmpty(): bool /** * @return static */ - abstract public function join(array $strings, string $lastGlue = null): self; + abstract public function join(array $strings, ?string $lastGlue = null): self; public function jsonSerialize(): string { @@ -477,7 +477,7 @@ abstract public function reverse(): self; /** * @return static */ - abstract public function slice(int $start = 0, int $length = null): self; + abstract public function slice(int $start = 0, ?int $length = null): self; /** * @return static @@ -487,12 +487,12 @@ abstract public function snake(): self; /** * @return static */ - abstract public function splice(string $replacement, int $start = 0, int $length = null): self; + abstract public function splice(string $replacement, int $start = 0, ?int $length = null): self; /** * @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.'); @@ -560,7 +560,7 @@ public function startsWith($prefix): bool */ abstract public function title(bool $allWords = false): self; - 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 80b8326..52123f5 100644 --- a/AbstractUnicodeString.php +++ b/AbstractUnicodeString.php @@ -203,7 +203,7 @@ public function folded(bool $compat = true): parent return $str; } - public function join(array $strings, string $lastGlue = null): parent + public function join(array $strings, ?string $lastGlue = null): parent { $str = clone $this; diff --git a/ByteString.php b/ByteString.php index 626d8c1..05170da 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)); @@ -213,7 +213,7 @@ public function isUtf8(): bool return '' === $this->string || preg_match('//u', $this->string); } - public function join(array $strings, string $lastGlue = null): parent + public function join(array $strings, ?string $lastGlue = null): parent { $str = clone $this; @@ -356,7 +356,7 @@ public function reverse(): parent return $str; } - public function slice(int $start = 0, int $length = null): parent + public function slice(int $start = 0, ?int $length = null): parent { $str = clone $this; $str->string = (string) substr($this->string, $start, $length ?? \PHP_INT_MAX); @@ -372,7 +372,7 @@ public function snake(): parent return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): parent + public function splice(string $replacement, int $start = 0, ?int $length = null): parent { $str = clone $this; $str->string = substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX); @@ -380,7 +380,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 = $limit ?? \PHP_INT_MAX) { throw new InvalidArgumentException('Split limit must be a positive integer.'); @@ -426,12 +426,12 @@ public function title(bool $allWords = false): parent 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 8ab9209..55c2aef 100644 --- a/CodePointString.php +++ b/CodePointString.php @@ -194,7 +194,7 @@ public function replace(string $from, string $to): AbstractString return $str; } - public function slice(int $start = 0, int $length = null): AbstractString + public function slice(int $start = 0, ?int $length = null): AbstractString { $str = clone $this; $str->string = mb_substr($this->string, $start, $length, 'UTF-8'); @@ -202,7 +202,7 @@ public function slice(int $start = 0, int $length = null): AbstractString return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): AbstractString + public function splice(string $replacement, int $start = 0, ?int $length = null): AbstractString { if (!preg_match('//u', $replacement)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); @@ -216,7 +216,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 = $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 5aecfeb..5eb7fc1 100644 --- a/Slugger/AsciiSlugger.php +++ b/Slugger/AsciiSlugger.php @@ -69,7 +69,7 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface /** * @param array|\Closure|null $symbolsMap */ - public function __construct(string $defaultLocale = null, $symbolsMap = null) + public function __construct(?string $defaultLocale = null, $symbolsMap = null) { if (null !== $symbolsMap && !\is_array($symbolsMap) && !$symbolsMap instanceof \Closure) { throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be array, Closure or null, "%s" given.', __METHOD__, \gettype($symbolsMap))); @@ -98,7 +98,7 @@ public function getLocale() /** * {@inheritdoc} */ - public function slug(string $string, string $separator = '-', string $locale = null): AbstractUnicodeString + public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString { $locale = $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 5d31273..8bde9bc 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), @@ -1083,7 +1083,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; @@ -1137,7 +1137,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 83b7d03..49e44f8 100644 --- a/Tests/AbstractUnicodeTestCase.php +++ b/Tests/AbstractUnicodeTestCase.php @@ -80,7 +80,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 89b5887..7656c33 100644 --- a/Tests/Slugger/AsciiSluggerTest.php +++ b/Tests/Slugger/AsciiSluggerTest.php @@ -38,7 +38,7 @@ public static function provideSlugTests(): iterable } /** @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 9b906c6..7d5b567 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -184,7 +184,7 @@ public function indexOfLast($needle, int $offset = 0): ?int return false === $i ? null : $i; } - public function join(array $strings, string $lastGlue = null): AbstractString + public function join(array $strings, ?string $lastGlue = null): AbstractString { $str = parent::join($strings, $lastGlue); normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); @@ -264,7 +264,7 @@ public function replaceMatches(string $fromRegexp, $to): AbstractString return $str; } - public function slice(int $start = 0, int $length = null): AbstractString + public function slice(int $start = 0, ?int $length = null): AbstractString { $str = clone $this; @@ -276,7 +276,7 @@ public function slice(int $start = 0, int $length = null): AbstractString return $str; } - public function splice(string $replacement, int $start = 0, int $length = null): AbstractString + public function splice(string $replacement, int $start = 0, ?int $length = null): AbstractString { $str = clone $this; @@ -295,7 +295,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 = $limit ?? 2147483647) { throw new InvalidArgumentException('Split limit must be a positive integer.');