Skip to content

Commit

Permalink
Switch implicit nullable types to explicit (#221)
Browse files Browse the repository at this point in the history
Fixes deprecation warnings on PHP 8.4
  • Loading branch information
NickDickinsonWilde authored Jan 13, 2025
1 parent f67131b commit 6372130
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/AddressFormat/AddressFormatHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class AddressFormatHelper
* ]
* @throws \ReflectionException
*/
public static function getGroupedFields(string $formatString, FieldOverrides $fieldOverrides = null): array
public static function getGroupedFields(string $formatString, ?FieldOverrides $fieldOverrides = null): array
{
$groupedFields = [];
$hiddenFields = $fieldOverrides ? $fieldOverrides->getHiddenFields() : [];
Expand Down
8 changes: 4 additions & 4 deletions src/Country/CountryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CountryRepository implements CountryRepositoryInterface
* @param string|null $definitionPath The path to the country definitions.
* Defaults to 'resources/country'.
*/
public function __construct(string $defaultLocale = 'en', string $fallbackLocale = 'en', string $definitionPath = null)
public function __construct(string $defaultLocale = 'en', string $fallbackLocale = 'en', ?string $definitionPath = null)
{
$this->defaultLocale = $defaultLocale;
$this->fallbackLocale = $fallbackLocale;
Expand All @@ -89,7 +89,7 @@ public function __construct(string $defaultLocale = 'en', string $fallbackLocale
/**
* {@inheritdoc}
*/
public function get(string $countryCode, string $locale = null): Country
public function get(string $countryCode, ?string $locale = null): Country
{
$countryCode = strtoupper($countryCode);
$baseDefinitions = $this->getBaseDefinitions();
Expand All @@ -112,7 +112,7 @@ public function get(string $countryCode, string $locale = null): Country
/**
* {@inheritdoc}
*/
public function getAll(string $locale = null): array
public function getAll(?string $locale = null): array
{
$locale = $locale ?: $this->defaultLocale;
$locale = Locale::resolve($this->availableLocales, $locale, $this->fallbackLocale);
Expand All @@ -136,7 +136,7 @@ public function getAll(string $locale = null): array
/**
* {@inheritdoc}
*/
public function getList(string $locale = null): array
public function getList(?string $locale = null): array
{
$locale = $locale ?: $this->defaultLocale;
$locale = Locale::resolve($this->availableLocales, $locale, $this->fallbackLocale);
Expand Down
6 changes: 3 additions & 3 deletions src/Country/CountryRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CountryRepositoryInterface
*
* @return Country
*/
public function get(string $countryCode, string $locale = null): Country;
public function get(string $countryCode, ?string $locale = null): Country;

/**
* Gets all countries.
Expand All @@ -24,7 +24,7 @@ public function get(string $countryCode, string $locale = null): Country;
*
* @return Country[] An array of countries, keyed by country code.
*/
public function getAll(string $locale = null): array;
public function getAll(?string $locale = null): array;

/**
* Gets a list of countries.
Expand All @@ -33,5 +33,5 @@ public function getAll(string $locale = null): array;
*
* @return string[] An array of country names, keyed by country code.
*/
public function getList(string $locale = null): array;
public function getList(?string $locale = null): array;
}
2 changes: 1 addition & 1 deletion src/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static function matchCandidates(?string $firstLocale, ?string $secondLoca
* @throws UnknownLocaleException
* @see self::getCandidates
*/
public static function resolve(array $availableLocales, string $locale, string $fallbackLocale = null): string
public static function resolve(array $availableLocales, string $locale, ?string $fallbackLocale = null): string
{
$locale = self::canonicalize($locale);
$resolvedLocale = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Subdivision/SubdivisionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SubdivisionRepository implements SubdivisionRepositoryInterface
* @param AddressFormatRepositoryInterface|null $addressFormatRepository The address format repository.
* @param null $definitionPath Path to the subdivision definitions.
*/
public function __construct(AddressFormatRepositoryInterface $addressFormatRepository = null, $definitionPath = null)
public function __construct(?AddressFormatRepositoryInterface $addressFormatRepository = null, $definitionPath = null)
{
$this->addressFormatRepository = $addressFormatRepository ?: new AddressFormatRepository();
$this->definitionPath = $definitionPath ?: __DIR__ . '/../../resources/subdivision/';
Expand Down Expand Up @@ -72,7 +72,7 @@ public function getAll(array $parents): array
/**
* {@inheritdoc}
*/
public function getList(array $parents, string $locale = null): array
public function getList(array $parents, ?string $locale = null): array
{
$definitions = $this->loadDefinitions($parents);
if (empty($definitions)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Subdivision/SubdivisionRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public function getAll(array $parents): array;
*
* @return array An array of subdivision names, keyed by code.
*/
public function getList(array $parents, string $locale = null): array;
public function getList(array $parents, ?string $locale = null): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AddressFormatConstraintValidator extends ConstraintValidator
/**
* Creates an AddressFormatValidator instance.
*/
public function __construct(AddressFormatRepositoryInterface $addressFormatRepository = null, SubdivisionRepositoryInterface $subdivisionRepository = null)
public function __construct(?AddressFormatRepositoryInterface $addressFormatRepository = null, ?SubdivisionRepositoryInterface $subdivisionRepository = null)
{
$this->addressFormatRepository = $addressFormatRepository ?: new AddressFormatRepository();
$this->subdivisionRepository = $subdivisionRepository ?: new SubdivisionRepository();
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Constraints/CountryConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CountryConstraintValidator extends ConstraintValidator
{
protected CountryRepositoryInterface $countryRepository;

public function __construct(CountryRepositoryInterface $countryRepository = null)
public function __construct(?CountryRepositoryInterface $countryRepository = null)
{
$this->countryRepository = $countryRepository ?: new CountryRepository();
}
Expand Down

0 comments on commit 6372130

Please sign in to comment.