Skip to content

Commit df4793d

Browse files
bug #467 Update nullable types for PHP 8.4 (mbeccati)
This PR was squashed before being merged into the 1.x branch. Discussion ---------- Update nullable types for PHP 8.4 The PR is meant to fix the deprecation notices raised since php/php-src@330cc5c I had tried to update the php-cs-fixer rule, but running the fixer is re-formatting all the method bodies and I couldn't figure out how to cleanly get the desired result, so I used a trusted editor and some preg-fu to get the desired result. Commits ------- aaaa1c9 Update nullable types for PHP 8.4
2 parents 6a71d4e + aaaa1c9 commit df4793d

20 files changed

+30
-29
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a7548a261ad4bcdb675adceb6604cf1681b1f6e2

src/Intl/Icu/DateFormat/Hour1200Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function format(\DateTime $dateTime, int $length): string
2828
return $this->padLeft($hourOfDay, $length);
2929
}
3030

31-
public function normalizeHour(int $hour, string $marker = null): int
31+
public function normalizeHour(int $hour, ?string $marker = null): int
3232
{
3333
if ('PM' === $marker) {
3434
$hour += 12;

src/Intl/Icu/DateFormat/Hour1201Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function format(\DateTime $dateTime, int $length): string
2525
return $this->padLeft($dateTime->format('g'), $length);
2626
}
2727

28-
public function normalizeHour(int $hour, string $marker = null): int
28+
public function normalizeHour(int $hour, ?string $marker = null): int
2929
{
3030
if ('PM' !== $marker && 12 === $hour) {
3131
$hour = 0;

src/Intl/Icu/DateFormat/Hour2400Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function format(\DateTime $dateTime, int $length): string
2525
return $this->padLeft($dateTime->format('G'), $length);
2626
}
2727

28-
public function normalizeHour(int $hour, string $marker = null): int
28+
public function normalizeHour(int $hour, ?string $marker = null): int
2929
{
3030
if ('AM' === $marker) {
3131
$hour = 0;

src/Intl/Icu/DateFormat/Hour2401Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function format(\DateTime $dateTime, int $length): string
2828
return $this->padLeft($hourOfDay, $length);
2929
}
3030

31-
public function normalizeHour(int $hour, string $marker = null): int
31+
public function normalizeHour(int $hour, ?string $marker = null): int
3232
{
3333
if ((null === $marker && 24 === $hour) || 'AM' === $marker) {
3434
$hour = 0;

src/Intl/Icu/DateFormat/HourTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ abstract class HourTransformer extends Transformer
2828
*
2929
* @return int The normalized hour value
3030
*/
31-
abstract public function normalizeHour(int $hour, string $marker = null): int;
31+
abstract public function normalizeHour(int $hour, ?string $marker = null): int;
3232
}

src/Intl/Icu/IntlDateFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function __construct(?string $locale, ?int $dateType, ?int $timeType, $ti
193193
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
194194
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
195195
*/
196-
public static function create(?string $locale, ?int $dateType, ?int $timeType, $timezone = null, int $calendar = null, ?string $pattern = '')
196+
public static function create(?string $locale, ?int $dateType, ?int $timeType, $timezone = null, ?int $calendar = null, ?string $pattern = '')
197197
{
198198
return new static($locale, $dateType, $timeType, $timezone, $calendar, $pattern);
199199
}
@@ -276,7 +276,7 @@ public function format($datetime)
276276
*
277277
* @throws MethodNotImplementedException
278278
*/
279-
public static function formatObject($datetime, $format = null, string $locale = null)
279+
public static function formatObject($datetime, $format = null, ?string $locale = null)
280280
{
281281
throw new MethodNotImplementedException(__METHOD__);
282282
}

src/Intl/Icu/Locale.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static function getDefault()
147147
*
148148
* @throws MethodNotImplementedException
149149
*/
150-
public static function getDisplayLanguage(string $locale, string $displayLocale = null)
150+
public static function getDisplayLanguage(string $locale, ?string $displayLocale = null)
151151
{
152152
throw new MethodNotImplementedException(__METHOD__);
153153
}
@@ -161,7 +161,7 @@ public static function getDisplayLanguage(string $locale, string $displayLocale
161161
*
162162
* @throws MethodNotImplementedException
163163
*/
164-
public static function getDisplayName(string $locale, string $displayLocale = null)
164+
public static function getDisplayName(string $locale, ?string $displayLocale = null)
165165
{
166166
throw new MethodNotImplementedException(__METHOD__);
167167
}
@@ -175,7 +175,7 @@ public static function getDisplayName(string $locale, string $displayLocale = nu
175175
*
176176
* @throws MethodNotImplementedException
177177
*/
178-
public static function getDisplayRegion(string $locale, string $displayLocale = null)
178+
public static function getDisplayRegion(string $locale, ?string $displayLocale = null)
179179
{
180180
throw new MethodNotImplementedException(__METHOD__);
181181
}
@@ -189,7 +189,7 @@ public static function getDisplayRegion(string $locale, string $displayLocale =
189189
*
190190
* @throws MethodNotImplementedException
191191
*/
192-
public static function getDisplayScript(string $locale, string $displayLocale = null)
192+
public static function getDisplayScript(string $locale, ?string $displayLocale = null)
193193
{
194194
throw new MethodNotImplementedException(__METHOD__);
195195
}
@@ -203,7 +203,7 @@ public static function getDisplayScript(string $locale, string $displayLocale =
203203
*
204204
* @throws MethodNotImplementedException
205205
*/
206-
public static function getDisplayVariant(string $locale, string $displayLocale = null)
206+
public static function getDisplayVariant(string $locale, ?string $displayLocale = null)
207207
{
208208
throw new MethodNotImplementedException(__METHOD__);
209209
}
@@ -271,7 +271,7 @@ public static function getScript(string $locale)
271271
*
272272
* @throws MethodNotImplementedException
273273
*/
274-
public static function lookup(array $languageTag, string $locale, bool $canonicalize = false, string $defaultLocale = null)
274+
public static function lookup(array $languageTag, string $locale, bool $canonicalize = false, ?string $defaultLocale = null)
275275
{
276276
throw new MethodNotImplementedException(__METHOD__);
277277
}

src/Intl/Icu/NumberFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ abstract class NumberFormatter
254254
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
255255
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
256256
*/
257-
public function __construct(?string $locale = 'en', int $style = null, string $pattern = null)
257+
public function __construct(?string $locale = 'en', ?int $style = null, ?string $pattern = null)
258258
{
259259
if ('en' !== $locale && null !== $locale) {
260260
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
293293
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
294294
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
295295
*/
296-
public static function create(?string $locale = 'en', int $style = null, string $pattern = null)
296+
public static function create(?string $locale = 'en', ?int $style = null, ?string $pattern = null)
297297
{
298298
return new static($locale, $style, $pattern);
299299
}

src/Mbstring/Mbstring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public static function mb_ord($s, $encoding = null)
827827
return $code;
828828
}
829829

830-
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string
830+
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
831831
{
832832
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) {
833833
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');

src/Php83/Php83.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function json_validate(string $json, int $depth = 512, int $flags
4040
return \JSON_ERROR_NONE === json_last_error();
4141
}
4242

43-
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string
43+
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
4444
{
4545
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) {
4646
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');

src/Php83/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function str_decrement(string $string): string { return p\Php83::str_decrement($
4040
}
4141

4242
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
43-
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); }
43+
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); }
4444
}
4545

4646
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {

src/Php83/bootstrap81.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515

1616
if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) {
17-
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); }
17+
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); }
1818
}
1919

2020
if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) {

src/Util/TestListenerForV7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestListenerForV7 extends TestSuite implements TestListenerInterface
2626
private $suite;
2727
private $trait;
2828

29-
public function __construct(TestSuite $suite = null)
29+
public function __construct(?TestSuite $suite = null)
3030
{
3131
if ($suite) {
3232
$this->suite = $suite;

src/Util/TestListenerForV9.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestListenerForV9 extends TestSuite implements TestListenerInterface
2323
private $suite;
2424
private $trait;
2525

26-
public function __construct(TestSuite $suite = null)
26+
public function __construct(?TestSuite $suite = null)
2727
{
2828
if ($suite) {
2929
$this->suite = $suite;
@@ -43,7 +43,7 @@ public function addError(Test $test, \Throwable $t, float $time): void
4343
$this->trait->addError($test, $t, $time);
4444
}
4545

46-
public function addWarning($test, Warning $e = null, float $time = null): void
46+
public function addWarning($test, ?Warning $e = null, ?float $time = null): void
4747
{
4848
if (\is_string($test)) {
4949
parent::addWarning($test);

tests/Intl/Icu/AbstractNumberFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ public function testParseWithNotNullPositionValue()
886886
/**
887887
* @return NumberFormatter|\NumberFormatter
888888
*/
889-
abstract protected static function getNumberFormatter(string $locale = 'en', string $style = null, string $pattern = null);
889+
abstract protected static function getNumberFormatter(string $locale = 'en', ?string $style = null, ?string $pattern = null);
890890

891891
abstract protected static function getIntlErrorMessage(): string;
892892

tests/Intl/Icu/NumberFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testSetTextAttribute()
171171
$formatter->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, '-');
172172
}
173173

174-
protected static function getNumberFormatter(?string $locale = 'en', string $style = null, string $pattern = null): NumberFormatter
174+
protected static function getNumberFormatter(?string $locale = 'en', ?string $style = null, ?string $pattern = null): NumberFormatter
175175
{
176176
return new class($locale, $style, $pattern) extends NumberFormatter {
177177
};

tests/Intl/Icu/Verification/NumberFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testGetTextAttribute()
4646
parent::testGetTextAttribute();
4747
}
4848

49-
protected static function getNumberFormatter(?string $locale = 'en', string $style = null, string $pattern = null): \NumberFormatter
49+
protected static function getNumberFormatter(?string $locale = 'en', ?string $style = null, ?string $pattern = null): \NumberFormatter
5050
{
5151
return new \NumberFormatter($locale, $style, $pattern);
5252
}

tests/Mbstring/MbstringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public function testDecodeMimeheader()
635635
* @dataProvider paddingEmojiProvider
636636
* @dataProvider paddingEncodingProvider
637637
*/
638-
public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, string $encoding = null): void
638+
public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void
639639
{
640640
if ('UTF-32' === $encoding && \PHP_VERSION_ID < 73000) {
641641
$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
649649
*
650650
* @dataProvider mbStrPadInvalidArgumentsProvider
651651
*/
652-
public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, string $encoding = null): void
652+
public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void
653653
{
654654
$this->expectException(\ValueError::class);
655655
$this->expectErrorMessage($expectedError);

tests/Php83/Php83Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testJsonValidate(bool $valid, string $json, string $errorMessage
3333
* @dataProvider paddingEmojiProvider
3434
* @dataProvider paddingEncodingProvider
3535
*/
36-
public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, string $encoding = null): void
36+
public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void
3737
{
3838
$this->assertSame($expectedResult, mb_convert_encoding(mb_str_pad($string, $length, $padString, $padType, $encoding), 'UTF-8', $encoding ?? mb_internal_encoding()));
3939
}
@@ -43,7 +43,7 @@ public function testMbStrPad(string $expectedResult, string $string, int $length
4343
*
4444
* @dataProvider mbStrPadInvalidArgumentsProvider
4545
*/
46-
public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, string $encoding = null): void
46+
public function testMbStrPadInvalidArguments(string $expectedError, string $string, int $length, string $padString, int $padType, ?string $encoding = null): void
4747
{
4848
$this->expectException(\ValueError::class);
4949
$this->expectErrorMessage($expectedError);

0 commit comments

Comments
 (0)