From aaaa1c99e3c9e40b26c9177a6d018d5a2aad8360 Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Thu, 14 Mar 2024 14:33:56 +0100 Subject: [PATCH] Update nullable types for PHP 8.4 --- .git-blame-ignore-revs | 1 + src/Intl/Icu/DateFormat/Hour1200Transformer.php | 2 +- src/Intl/Icu/DateFormat/Hour1201Transformer.php | 2 +- src/Intl/Icu/DateFormat/Hour2400Transformer.php | 2 +- src/Intl/Icu/DateFormat/Hour2401Transformer.php | 2 +- src/Intl/Icu/DateFormat/HourTransformer.php | 2 +- src/Intl/Icu/IntlDateFormatter.php | 4 ++-- src/Intl/Icu/Locale.php | 12 ++++++------ src/Intl/Icu/NumberFormatter.php | 4 ++-- src/Mbstring/Mbstring.php | 2 +- src/Php83/Php83.php | 2 +- src/Php83/bootstrap.php | 2 +- src/Php83/bootstrap81.php | 2 +- src/Util/TestListenerForV7.php | 2 +- src/Util/TestListenerForV9.php | 4 ++-- tests/Intl/Icu/AbstractNumberFormatterTest.php | 2 +- tests/Intl/Icu/NumberFormatterTest.php | 2 +- tests/Intl/Icu/Verification/NumberFormatterTest.php | 2 +- tests/Mbstring/MbstringTest.php | 4 ++-- tests/Php83/Php83Test.php | 4 ++-- 20 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..72f772d6 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +a7548a261ad4bcdb675adceb6604cf1681b1f6e2 diff --git a/src/Intl/Icu/DateFormat/Hour1200Transformer.php b/src/Intl/Icu/DateFormat/Hour1200Transformer.php index 839632a9..68891a79 100644 --- a/src/Intl/Icu/DateFormat/Hour1200Transformer.php +++ b/src/Intl/Icu/DateFormat/Hour1200Transformer.php @@ -28,7 +28,7 @@ public function format(\DateTime $dateTime, int $length): string return $this->padLeft($hourOfDay, $length); } - public function normalizeHour(int $hour, string $marker = null): int + public function normalizeHour(int $hour, ?string $marker = null): int { if ('PM' === $marker) { $hour += 12; diff --git a/src/Intl/Icu/DateFormat/Hour1201Transformer.php b/src/Intl/Icu/DateFormat/Hour1201Transformer.php index 12c0694d..4ac9b2a3 100644 --- a/src/Intl/Icu/DateFormat/Hour1201Transformer.php +++ b/src/Intl/Icu/DateFormat/Hour1201Transformer.php @@ -25,7 +25,7 @@ public function format(\DateTime $dateTime, int $length): string return $this->padLeft($dateTime->format('g'), $length); } - public function normalizeHour(int $hour, string $marker = null): int + public function normalizeHour(int $hour, ?string $marker = null): int { if ('PM' !== $marker && 12 === $hour) { $hour = 0; diff --git a/src/Intl/Icu/DateFormat/Hour2400Transformer.php b/src/Intl/Icu/DateFormat/Hour2400Transformer.php index 32f585f8..bc259e28 100644 --- a/src/Intl/Icu/DateFormat/Hour2400Transformer.php +++ b/src/Intl/Icu/DateFormat/Hour2400Transformer.php @@ -25,7 +25,7 @@ public function format(\DateTime $dateTime, int $length): string return $this->padLeft($dateTime->format('G'), $length); } - public function normalizeHour(int $hour, string $marker = null): int + public function normalizeHour(int $hour, ?string $marker = null): int { if ('AM' === $marker) { $hour = 0; diff --git a/src/Intl/Icu/DateFormat/Hour2401Transformer.php b/src/Intl/Icu/DateFormat/Hour2401Transformer.php index e7c8bb0a..f8d3367b 100644 --- a/src/Intl/Icu/DateFormat/Hour2401Transformer.php +++ b/src/Intl/Icu/DateFormat/Hour2401Transformer.php @@ -28,7 +28,7 @@ public function format(\DateTime $dateTime, int $length): string return $this->padLeft($hourOfDay, $length); } - public function normalizeHour(int $hour, string $marker = null): int + public function normalizeHour(int $hour, ?string $marker = null): int { if ((null === $marker && 24 === $hour) || 'AM' === $marker) { $hour = 0; diff --git a/src/Intl/Icu/DateFormat/HourTransformer.php b/src/Intl/Icu/DateFormat/HourTransformer.php index b042ccf7..e973db18 100644 --- a/src/Intl/Icu/DateFormat/HourTransformer.php +++ b/src/Intl/Icu/DateFormat/HourTransformer.php @@ -28,5 +28,5 @@ abstract class HourTransformer extends Transformer * * @return int The normalized hour value */ - abstract public function normalizeHour(int $hour, string $marker = null): int; + abstract public function normalizeHour(int $hour, ?string $marker = null): int; } diff --git a/src/Intl/Icu/IntlDateFormatter.php b/src/Intl/Icu/IntlDateFormatter.php index e878fe67..b2674f90 100644 --- a/src/Intl/Icu/IntlDateFormatter.php +++ b/src/Intl/Icu/IntlDateFormatter.php @@ -193,7 +193,7 @@ public function __construct(?string $locale, ?int $dateType, ?int $timeType, $ti * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed * @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed */ - public static function create(?string $locale, ?int $dateType, ?int $timeType, $timezone = null, int $calendar = null, ?string $pattern = '') + public static function create(?string $locale, ?int $dateType, ?int $timeType, $timezone = null, ?int $calendar = null, ?string $pattern = '') { return new static($locale, $dateType, $timeType, $timezone, $calendar, $pattern); } @@ -276,7 +276,7 @@ public function format($datetime) * * @throws MethodNotImplementedException */ - public static function formatObject($datetime, $format = null, string $locale = null) + public static function formatObject($datetime, $format = null, ?string $locale = null) { throw new MethodNotImplementedException(__METHOD__); } diff --git a/src/Intl/Icu/Locale.php b/src/Intl/Icu/Locale.php index 2b63f9e6..f449fd5d 100644 --- a/src/Intl/Icu/Locale.php +++ b/src/Intl/Icu/Locale.php @@ -147,7 +147,7 @@ public static function getDefault() * * @throws MethodNotImplementedException */ - public static function getDisplayLanguage(string $locale, string $displayLocale = null) + public static function getDisplayLanguage(string $locale, ?string $displayLocale = null) { throw new MethodNotImplementedException(__METHOD__); } @@ -161,7 +161,7 @@ public static function getDisplayLanguage(string $locale, string $displayLocale * * @throws MethodNotImplementedException */ - public static function getDisplayName(string $locale, string $displayLocale = null) + public static function getDisplayName(string $locale, ?string $displayLocale = null) { throw new MethodNotImplementedException(__METHOD__); } @@ -175,7 +175,7 @@ public static function getDisplayName(string $locale, string $displayLocale = nu * * @throws MethodNotImplementedException */ - public static function getDisplayRegion(string $locale, string $displayLocale = null) + public static function getDisplayRegion(string $locale, ?string $displayLocale = null) { throw new MethodNotImplementedException(__METHOD__); } @@ -189,7 +189,7 @@ public static function getDisplayRegion(string $locale, string $displayLocale = * * @throws MethodNotImplementedException */ - public static function getDisplayScript(string $locale, string $displayLocale = null) + public static function getDisplayScript(string $locale, ?string $displayLocale = null) { throw new MethodNotImplementedException(__METHOD__); } @@ -203,7 +203,7 @@ public static function getDisplayScript(string $locale, string $displayLocale = * * @throws MethodNotImplementedException */ - public static function getDisplayVariant(string $locale, string $displayLocale = null) + public static function getDisplayVariant(string $locale, ?string $displayLocale = null) { throw new MethodNotImplementedException(__METHOD__); } @@ -271,7 +271,7 @@ public static function getScript(string $locale) * * @throws MethodNotImplementedException */ - public static function lookup(array $languageTag, string $locale, bool $canonicalize = false, string $defaultLocale = null) + public static function lookup(array $languageTag, string $locale, bool $canonicalize = false, ?string $defaultLocale = null) { throw new MethodNotImplementedException(__METHOD__); } diff --git a/src/Intl/Icu/NumberFormatter.php b/src/Intl/Icu/NumberFormatter.php index 9c79e3f3..5b247066 100644 --- a/src/Intl/Icu/NumberFormatter.php +++ b/src/Intl/Icu/NumberFormatter.php @@ -254,7 +254,7 @@ abstract class NumberFormatter * @throws MethodArgumentValueNotImplementedException When the $style is not supported * @throws MethodArgumentNotImplementedException When the pattern value is different than null */ - public function __construct(?string $locale = 'en', int $style = null, string $pattern = null) + public function __construct(?string $locale = 'en', ?int $style = null, ?string $pattern = null) { if ('en' !== $locale && null !== $locale) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported'); @@ -293,7 +293,7 @@ public function __construct(?string $locale = 'en', int $style = null, string $p * @throws MethodArgumentValueNotImplementedException When the $style is not supported * @throws MethodArgumentNotImplementedException When the pattern value is different than null */ - public static function create(?string $locale = 'en', int $style = null, string $pattern = null) + public static function create(?string $locale = 'en', ?int $style = null, ?string $pattern = null) { return new static($locale, $style, $pattern); } diff --git a/src/Mbstring/Mbstring.php b/src/Mbstring/Mbstring.php index 2e0b9694..04b35cb8 100644 --- a/src/Mbstring/Mbstring.php +++ b/src/Mbstring/Mbstring.php @@ -827,7 +827,7 @@ public static function mb_ord($s, $encoding = null) return $code; } - public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string + public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string { if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) { throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH'); diff --git a/src/Php83/Php83.php b/src/Php83/Php83.php index 209172bf..9393f23e 100644 --- a/src/Php83/Php83.php +++ b/src/Php83/Php83.php @@ -40,7 +40,7 @@ public static function json_validate(string $json, int $depth = 512, int $flags return \JSON_ERROR_NONE === json_last_error(); } - public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string + public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string { if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) { throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH'); diff --git a/src/Php83/bootstrap.php b/src/Php83/bootstrap.php index bcb70e48..f43af17e 100644 --- a/src/Php83/bootstrap.php +++ b/src/Php83/bootstrap.php @@ -40,7 +40,7 @@ function str_decrement(string $string): string { return p\Php83::str_decrement($ } if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) { - function ldap_exop_sync($ldap, string $request_oid, string $request_data = null, array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } + function ldap_exop_sync($ldap, string $request_oid, ?string $request_data = null, ?array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } } if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) { diff --git a/src/Php83/bootstrap81.php b/src/Php83/bootstrap81.php index 63a4f780..68395b43 100644 --- a/src/Php83/bootstrap81.php +++ b/src/Php83/bootstrap81.php @@ -14,7 +14,7 @@ } if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) { - function ldap_exop_sync(\LDAP\Connection $ldap, string $request_oid, string $request_data = null, array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } + function ldap_exop_sync(\LDAP\Connection $ldap, string $request_oid, ?string $request_data = null, ?array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } } if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) { diff --git a/src/Util/TestListenerForV7.php b/src/Util/TestListenerForV7.php index a5c3759b..73850783 100644 --- a/src/Util/TestListenerForV7.php +++ b/src/Util/TestListenerForV7.php @@ -26,7 +26,7 @@ class TestListenerForV7 extends TestSuite implements TestListenerInterface private $suite; private $trait; - public function __construct(TestSuite $suite = null) + public function __construct(?TestSuite $suite = null) { if ($suite) { $this->suite = $suite; diff --git a/src/Util/TestListenerForV9.php b/src/Util/TestListenerForV9.php index 3e5d722f..04a5f6be 100644 --- a/src/Util/TestListenerForV9.php +++ b/src/Util/TestListenerForV9.php @@ -23,7 +23,7 @@ class TestListenerForV9 extends TestSuite implements TestListenerInterface private $suite; private $trait; - public function __construct(TestSuite $suite = null) + public function __construct(?TestSuite $suite = null) { if ($suite) { $this->suite = $suite; @@ -43,7 +43,7 @@ public function addError(Test $test, \Throwable $t, float $time): void $this->trait->addError($test, $t, $time); } - public function addWarning($test, Warning $e = null, float $time = null): void + public function addWarning($test, ?Warning $e = null, ?float $time = null): void { if (\is_string($test)) { parent::addWarning($test); diff --git a/tests/Intl/Icu/AbstractNumberFormatterTest.php b/tests/Intl/Icu/AbstractNumberFormatterTest.php index b9300c51..e5f47079 100644 --- a/tests/Intl/Icu/AbstractNumberFormatterTest.php +++ b/tests/Intl/Icu/AbstractNumberFormatterTest.php @@ -886,7 +886,7 @@ public function testParseWithNotNullPositionValue() /** * @return NumberFormatter|\NumberFormatter */ - abstract protected static function getNumberFormatter(string $locale = 'en', string $style = null, string $pattern = null); + abstract protected static function getNumberFormatter(string $locale = 'en', ?string $style = null, ?string $pattern = null); abstract protected static function getIntlErrorMessage(): string; diff --git a/tests/Intl/Icu/NumberFormatterTest.php b/tests/Intl/Icu/NumberFormatterTest.php index 724e8cb5..8b6dd92f 100644 --- a/tests/Intl/Icu/NumberFormatterTest.php +++ b/tests/Intl/Icu/NumberFormatterTest.php @@ -171,7 +171,7 @@ public function testSetTextAttribute() $formatter->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, '-'); } - protected static function getNumberFormatter(?string $locale = 'en', string $style = null, string $pattern = null): NumberFormatter + protected static function getNumberFormatter(?string $locale = 'en', ?string $style = null, ?string $pattern = null): NumberFormatter { return new class($locale, $style, $pattern) extends NumberFormatter { }; diff --git a/tests/Intl/Icu/Verification/NumberFormatterTest.php b/tests/Intl/Icu/Verification/NumberFormatterTest.php index 1986fda7..38afae2e 100644 --- a/tests/Intl/Icu/Verification/NumberFormatterTest.php +++ b/tests/Intl/Icu/Verification/NumberFormatterTest.php @@ -46,7 +46,7 @@ public function testGetTextAttribute() parent::testGetTextAttribute(); } - protected static function getNumberFormatter(?string $locale = 'en', string $style = null, string $pattern = null): \NumberFormatter + protected static function getNumberFormatter(?string $locale = 'en', ?string $style = null, ?string $pattern = null): \NumberFormatter { return new \NumberFormatter($locale, $style, $pattern); } diff --git a/tests/Mbstring/MbstringTest.php b/tests/Mbstring/MbstringTest.php index 2499bed1..88cfc326 100644 --- a/tests/Mbstring/MbstringTest.php +++ b/tests/Mbstring/MbstringTest.php @@ -635,7 +635,7 @@ public function testDecodeMimeheader() * @dataProvider paddingEmojiProvider * @dataProvider paddingEncodingProvider */ - public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, string $encoding = null): void + public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void { if ('UTF-32' === $encoding && \PHP_VERSION_ID < 73000) { $this->markTestSkipped('PHP < 7.3 doesn\'t handle UTF-32 encoding properly'); @@ -649,7 +649,7 @@ public function testMbStrPad(string $expectedResult, string $string, int $length * * @dataProvider mbStrPadInvalidArgumentsProvider */ - public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, string $encoding = null): void + public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void { $this->expectException(\ValueError::class); $this->expectErrorMessage($expectedError); diff --git a/tests/Php83/Php83Test.php b/tests/Php83/Php83Test.php index dfb4c6d7..4ee28dff 100644 --- a/tests/Php83/Php83Test.php +++ b/tests/Php83/Php83Test.php @@ -33,7 +33,7 @@ public function testJsonValidate(bool $valid, string $json, string $errorMessage * @dataProvider paddingEmojiProvider * @dataProvider paddingEncodingProvider */ - public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, string $encoding = null): void + public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void { $this->assertSame($expectedResult, mb_convert_encoding(mb_str_pad($string, $length, $padString, $padType, $encoding), 'UTF-8', $encoding ?? mb_internal_encoding())); } @@ -43,7 +43,7 @@ public function testMbStrPad(string $expectedResult, string $string, int $length * * @dataProvider mbStrPadInvalidArgumentsProvider */ - public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, string $encoding = null): void + public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void { $this->expectException(\ValueError::class); $this->expectErrorMessage($expectedError);