From 56a7fb2433478f0dc886aeddd234e4f3f4c17774 Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 22 Jan 2024 22:50:30 +0000 Subject: [PATCH] Fix `RiskyTruthyFalsyComparison` issues Signed-off-by: George Steel --- src/PhoneNumberValue.php | 2 +- src/Validator/PhoneNumber.php | 2 +- src/View/Helper/PhoneNumberFormat.php | 2 +- test/ProjectIntegrationTestCase.php | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PhoneNumberValue.php b/src/PhoneNumberValue.php index 826f317..21fd9fc 100644 --- a/src/PhoneNumberValue.php +++ b/src/PhoneNumberValue.php @@ -190,7 +190,7 @@ public function type(): int private static function regionCodeForNumber(LibPhoneNumber $number, ?string $givenCode): ?string { $dialingCode = $number->getCountryCode(); - if (! $dialingCode) { + if ($dialingCode === null) { return $givenCode; } diff --git a/src/Validator/PhoneNumber.php b/src/Validator/PhoneNumber.php index 959ee25..b6f52c2 100644 --- a/src/Validator/PhoneNumber.php +++ b/src/Validator/PhoneNumber.php @@ -190,7 +190,7 @@ public function setAllowedTypes(int $types): void /** @param array $validationContext */ private function resolveCountry(?array $validationContext): ?CountryCode { - if (! is_array($validationContext) || ! $this->countryContext) { + if (! is_array($validationContext) || $this->countryContext === null) { return $this->country; } diff --git a/src/View/Helper/PhoneNumberFormat.php b/src/View/Helper/PhoneNumberFormat.php index 98ba95a..5832710 100644 --- a/src/View/Helper/PhoneNumberFormat.php +++ b/src/View/Helper/PhoneNumberFormat.php @@ -25,7 +25,7 @@ public function __invoke(): self */ private function coalesceCountryCode(?string $countryCodeOrLocale): CountryCode { - $code = $countryCodeOrLocale ? CountryCode::tryFromString($countryCodeOrLocale) : null; + $code = $countryCodeOrLocale !== null ? CountryCode::tryFromString($countryCodeOrLocale) : null; return $code ?? $this->defaultCountryCode; } diff --git a/test/ProjectIntegrationTestCase.php b/test/ProjectIntegrationTestCase.php index 707b3e3..39976bd 100644 --- a/test/ProjectIntegrationTestCase.php +++ b/test/ProjectIntegrationTestCase.php @@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use function is_array; + /** * @psalm-import-type ServiceManagerConfigurationType from Laminas\ServiceManager\ConfigInterface * @phpcs:disable WebimpressCodingStandard.NamingConventions.AbstractClass.Prefix @@ -32,9 +34,9 @@ protected static function getContainer(array $userConfig = []): ContainerInterfa $config = $aggregator->getMergedConfig(); $dependencies = $config['dependencies'] ?? []; self::assertIsArray($dependencies); - /** @psalm-var ServiceManagerConfigurationType $dependencies */ - unset($dependencies['services']['config']); + /** @psalm-suppress MixedArrayAssignment */ $dependencies['services']['config'] = $config; + /** @psalm-var ServiceManagerConfigurationType $dependencies */ return new Laminas\ServiceManager\ServiceManager($dependencies); }