From 0d7ce622f327f60a957db37410d638982aec1652 Mon Sep 17 00:00:00 2001 From: Joshua Gigg Date: Tue, 8 Oct 2024 09:47:39 +0100 Subject: [PATCH] PHP 8.4 compatibility Fixes #653 --- build/BuildMetadataFromXml.php | 4 ++-- src/PhoneNumberMatcher.php | 2 +- src/PhoneNumberUtil.php | 16 ++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build/BuildMetadataFromXml.php b/build/BuildMetadataFromXml.php index bbfb7eb2..5c400790 100644 --- a/build/BuildMetadataFromXml.php +++ b/build/BuildMetadataFromXml.php @@ -615,7 +615,7 @@ public static function setPossibleLengthsGeneralDesc(PhoneNumberDesc $generalDes * @param array $lengths * @param array $localOnlyLengths */ - private static function setPossibleLengths($lengths, $localOnlyLengths, PhoneNumberDesc $parentDesc = null, PhoneNumberDesc $desc) + private static function setPossibleLengths($lengths, $localOnlyLengths, ?PhoneNumberDesc $parentDesc, PhoneNumberDesc $desc) { // We clear these fields since the metadata tends to inherit from the parent element for other // fields (via a mergeFrom). @@ -679,7 +679,7 @@ private static function setPossibleLengths($lengths, $localOnlyLengths, PhoneNum * @return PhoneNumberDesc complete description of that phone number type */ public static function processPhoneNumberDescElement( - PhoneNumberDesc $parentDesc = null, + ?PhoneNumberDesc $parentDesc, \DOMElement $countryElement, $numberType ) { diff --git a/src/PhoneNumberMatcher.php b/src/PhoneNumberMatcher.php index cc407123..c960e7ae 100644 --- a/src/PhoneNumberMatcher.php +++ b/src/PhoneNumberMatcher.php @@ -622,7 +622,7 @@ public static function allNumberGroupsAreExactlyPresent( protected static function getNationalNumberGroups( PhoneNumberUtil $util, PhoneNumber $number, - NumberFormat $formattingPattern = null + ?NumberFormat $formattingPattern = null ) { if ($formattingPattern === null) { // This will be in the format +CC-DG;ext=EXT where DG represents groups of digits. diff --git a/src/PhoneNumberUtil.php b/src/PhoneNumberUtil.php index 73636786..aac0eb5c 100644 --- a/src/PhoneNumberUtil.php +++ b/src/PhoneNumberUtil.php @@ -428,8 +428,12 @@ protected function __construct(MetadataSourceInterface $metadataSource, $country * @param string|null $baseFileLocation * @return PhoneNumberUtil instance */ - public static function getInstance($baseFileLocation = null, array $countryCallingCodeToRegionCodeMap = null, MetadataLoaderInterface $metadataLoader = null, MetadataSourceInterface $metadataSource = null) - { + public static function getInstance( + $baseFileLocation = null, + ?array $countryCallingCodeToRegionCodeMap = null, + ?MetadataLoaderInterface $metadataLoader = null, + ?MetadataSourceInterface $metadataSource = null + ) { if (static::$instance === null) { if ($countryCallingCodeToRegionCodeMap === null) { $countryCallingCodeToRegionCodeMap = CountryCodeToRegionCodeMap::$countryCodeToRegionCodeMap; @@ -1576,7 +1580,7 @@ protected function maybeStripExtension(&$number) * as that of the default region supplied. * @return PhoneNumber a phone number proto buffer filled with the parsed number */ - public function parseAndKeepRawInput($numberToParse, $defaultRegion, PhoneNumber $phoneNumber = null) + public function parseAndKeepRawInput($numberToParse, $defaultRegion, ?PhoneNumber $phoneNumber = null) { if ($phoneNumber === null) { $phoneNumber = new PhoneNumber(); @@ -1594,7 +1598,7 @@ public function parseAndKeepRawInput($numberToParse, $defaultRegion, PhoneNumber * @param int $maxTries Defaults to PHP_INT_MAX * @return PhoneNumberMatcher */ - public function findNumbers($text, $defaultRegion, AbstractLeniency $leniency = null, $maxTries = PHP_INT_MAX) + public function findNumbers($text, $defaultRegion, ?AbstractLeniency $leniency = null, $maxTries = PHP_INT_MAX) { if ($leniency === null) { $leniency = Leniency::VALID(); @@ -2030,7 +2034,7 @@ protected function checkRegionForParsing($numberToParse, $defaultRegion) */ public function maybeExtractCountryCode( $number, - PhoneMetadata $defaultRegionMetadata = null, + ?PhoneMetadata $defaultRegionMetadata, &$nationalNumber, $keepRawInput, PhoneNumber $phoneNumber @@ -3166,7 +3170,7 @@ public function isValidNumberForRegion(PhoneNumber $number, $regionCode) * and the number is not in international format (does not start * with +) */ - public function parse($numberToParse, $defaultRegion = null, PhoneNumber $phoneNumber = null, $keepRawInput = false) + public function parse($numberToParse, $defaultRegion = null, ?PhoneNumber $phoneNumber = null, $keepRawInput = false) { if ($phoneNumber === null) { $phoneNumber = new PhoneNumber();