Skip to content

Commit

Permalink
bug #467 Update nullable types for PHP 8.4 (mbeccati)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolas-grekas committed Mar 14, 2024
2 parents 6a71d4e + aaaa1c9 commit df4793d
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a7548a261ad4bcdb675adceb6604cf1681b1f6e2
2 changes: 1 addition & 1 deletion src/Intl/Icu/DateFormat/Hour1200Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Intl/Icu/DateFormat/Hour1201Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Intl/Icu/DateFormat/Hour2400Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Intl/Icu/DateFormat/Hour2401Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Intl/Icu/DateFormat/HourTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Intl/Icu/IntlDateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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__);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Intl/Icu/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand Down Expand Up @@ -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__);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Intl/Icu/NumberFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mbstring/Mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Php83/Php83.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Php83/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Php83/bootstrap81.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Util/TestListenerForV7.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Util/TestListenerForV9.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Intl/Icu/AbstractNumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/Intl/Icu/NumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
};
Expand Down
2 changes: 1 addition & 1 deletion tests/Intl/Icu/Verification/NumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Mbstring/MbstringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Php83/Php83Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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);
Expand Down

0 comments on commit df4793d

Please sign in to comment.