From aefb6c199c8d870035ef2cc533cc958a6475b034 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 30 Apr 2024 01:35:41 +0200 Subject: [PATCH] Fix PHPStan on PHP 8.0 --- phpstan.neon.dist | 14 +++----------- src/Checker/ChannelEligibilityChecker.php | 9 ++++++--- src/Checker/DefaultEligibilityChecker.php | 6 ++---- src/Checker/SameBaseCountryEligibilityChecker.php | 9 ++++++--- src/Checker/VatNumberEligibilityChecker.php | 9 ++++++--- src/Checker/VatRateEligibilityCheckerInterface.php | 6 ++---- src/Fixture/Factory/AddressExampleFactory.php | 4 ++-- .../Factory/EuropeanChannelExampleFactory.php | 12 +++--------- 8 files changed, 30 insertions(+), 39 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 435d689..b6a70ed 100755 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,17 +6,9 @@ parameters: paths: - src - - tests - - excludePaths: - # Makes PHPStan crash - - src/DependencyInjection/Configuration.php - - - tests/Application/Kernel.php - - tests/Application/public/index.php - - tests/Application/config/**.php - - tests/Application/var/**.php - - tests/Application/node_modules/**.php + - tests/Application/src + - tests/Behat + - tests/Unit ignoreErrors: - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' diff --git a/src/Checker/ChannelEligibilityChecker.php b/src/Checker/ChannelEligibilityChecker.php index 46cb1b6..2135176 100644 --- a/src/Checker/ChannelEligibilityChecker.php +++ b/src/Checker/ChannelEligibilityChecker.php @@ -5,7 +5,6 @@ namespace FluxSE\SyliusEUVatPlugin\Checker; use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; -use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Sylius\Component\Addressing\Matcher\ZoneMatcherInterface; use Sylius\Component\Addressing\Model\Scope; use Sylius\Component\Addressing\Model\ZoneInterface; @@ -20,9 +19,13 @@ public function __construct( } public function check( - VATNumberAwareInterface&AddressInterface $taxationAddress, - ChannelInterface&EuropeanChannelAwareInterface $channel, + AddressInterface $taxationAddress, + ChannelInterface $channel, ): bool { + if (false === $channel instanceof EuropeanChannelAwareInterface) { + return false; + } + $channelEUZone = $channel->getEuropeanZone(); if (null === $channelEUZone) { return false; diff --git a/src/Checker/DefaultEligibilityChecker.php b/src/Checker/DefaultEligibilityChecker.php index 5ecd7db..45edaed 100644 --- a/src/Checker/DefaultEligibilityChecker.php +++ b/src/Checker/DefaultEligibilityChecker.php @@ -4,8 +4,6 @@ namespace FluxSE\SyliusEUVatPlugin\Checker; -use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; -use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -20,8 +18,8 @@ public function __construct( } public function check( - VATNumberAwareInterface&AddressInterface $taxationAddress, - ChannelInterface&EuropeanChannelAwareInterface $channel, + AddressInterface $taxationAddress, + ChannelInterface $channel, ): bool { foreach ($this->checkers as $checker) { if (false === $checker->check($taxationAddress, $channel)) { diff --git a/src/Checker/SameBaseCountryEligibilityChecker.php b/src/Checker/SameBaseCountryEligibilityChecker.php index 0da1f9d..8dd20de 100644 --- a/src/Checker/SameBaseCountryEligibilityChecker.php +++ b/src/Checker/SameBaseCountryEligibilityChecker.php @@ -5,21 +5,24 @@ namespace FluxSE\SyliusEUVatPlugin\Checker; use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; -use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\ChannelInterface; final class SameBaseCountryEligibilityChecker implements VatRateEligibilityCheckerInterface { public function check( - VATNumberAwareInterface&AddressInterface $taxationAddress, - ChannelInterface&EuropeanChannelAwareInterface $channel, + AddressInterface $taxationAddress, + ChannelInterface $channel, ): bool { $taxationCountryCode = $taxationAddress->getCountryCode(); if (null === $taxationCountryCode) { return false; } + if (false === $channel instanceof EuropeanChannelAwareInterface) { + return false; + } + if (true === $this->isBaseCountrySameAsCountryCode($channel, $taxationCountryCode)) { return false; } diff --git a/src/Checker/VatNumberEligibilityChecker.php b/src/Checker/VatNumberEligibilityChecker.php index e27f6d8..eb161d6 100644 --- a/src/Checker/VatNumberEligibilityChecker.php +++ b/src/Checker/VatNumberEligibilityChecker.php @@ -4,7 +4,6 @@ namespace FluxSE\SyliusEUVatPlugin\Checker; -use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Prometee\VIESClient\Util\VatNumberUtil; use Sylius\Component\Core\Model\AddressInterface; @@ -13,14 +12,18 @@ final class VatNumberEligibilityChecker implements VatRateEligibilityCheckerInterface { public function check( - VATNumberAwareInterface&AddressInterface $taxationAddress, - ChannelInterface&EuropeanChannelAwareInterface $channel, + AddressInterface $taxationAddress, + ChannelInterface $channel, ): bool { $taxationCountryCode = $taxationAddress->getCountryCode(); if (null === $taxationCountryCode) { return false; } + if (false === $taxationAddress instanceof VATNumberAwareInterface) { + return false; + } + $taxationVatNumber = $taxationAddress->getVatNumber(); if (null === $taxationVatNumber) { return false; diff --git a/src/Checker/VatRateEligibilityCheckerInterface.php b/src/Checker/VatRateEligibilityCheckerInterface.php index 9bd2736..f87fb58 100644 --- a/src/Checker/VatRateEligibilityCheckerInterface.php +++ b/src/Checker/VatRateEligibilityCheckerInterface.php @@ -4,15 +4,13 @@ namespace FluxSE\SyliusEUVatPlugin\Checker; -use FluxSE\SyliusEUVatPlugin\Entity\EuropeanChannelAwareInterface; -use FluxSE\SyliusEUVatPlugin\Entity\VATNumberAwareInterface; use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\ChannelInterface; interface VatRateEligibilityCheckerInterface { public function check( - AddressInterface&VATNumberAwareInterface $taxationAddress, - ChannelInterface&EuropeanChannelAwareInterface $channel, + AddressInterface $taxationAddress, + ChannelInterface $channel, ): bool; } diff --git a/src/Fixture/Factory/AddressExampleFactory.php b/src/Fixture/Factory/AddressExampleFactory.php index bc8b436..64338bc 100644 --- a/src/Fixture/Factory/AddressExampleFactory.php +++ b/src/Fixture/Factory/AddressExampleFactory.php @@ -18,7 +18,7 @@ class AddressExampleFactory extends BaseAddressExampleFactory { /** - * @param FactoryInterface $addressFactory + * @param FactoryInterface $addressFactory * @param RepositoryInterface $countryRepository * @param RepositoryInterface $customerRepository */ @@ -47,7 +47,7 @@ protected function configureOptions(OptionsResolver $resolver): void ; } - public function create(array $options = []): AddressInterface&VATNumberAwareInterface + public function create(array $options = []): AddressInterface { $address = parent::create($options); diff --git a/src/Fixture/Factory/EuropeanChannelExampleFactory.php b/src/Fixture/Factory/EuropeanChannelExampleFactory.php index 4149b87..9a60bc8 100644 --- a/src/Fixture/Factory/EuropeanChannelExampleFactory.php +++ b/src/Fixture/Factory/EuropeanChannelExampleFactory.php @@ -11,7 +11,6 @@ use Sylius\Component\Addressing\Model\ZoneInterface; use Sylius\Component\Channel\Context\ChannelNotFoundException; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; -use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Webmozart\Assert\Assert; @@ -21,9 +20,6 @@ class EuropeanChannelExampleFactory extends AbstractExampleFactory private OptionsResolver $optionsResolver; public function __construct( - /** - * @var ChannelRepositoryInterface - */ private ChannelRepositoryInterface $channelRepository, /** * @var RepositoryInterface @@ -39,19 +35,17 @@ public function __construct( $this->configureOptions($this->optionsResolver); } - public function create(array $options = []): ChannelInterface&EuropeanChannelAwareInterface + public function create(array $options = []): EuropeanChannelAwareInterface { $options = $this->optionsResolver->resolve($options); - /** @var ChannelInterface|null $channel */ + /** @var EuropeanChannelAwareInterface|null $channel */ $channel = $options['channel'] ?? null; if (null === $channel) { throw new ChannelNotFoundException('Channel has not been found, please create it before adding this fixture !'); } - Assert::isInstanceOf($channel, EuropeanChannelAwareInterface::class); - $baseCountry = $options['base_country'] ?? null; if (null !== $baseCountry) { Assert::isInstanceOf($baseCountry, CountryInterface::class); @@ -75,7 +69,7 @@ protected function configureOptions(OptionsResolver $resolver): void 'base_country', 'european_zone', ]) - ->setAllowedTypes('channel', ['string', ChannelInterface::class]) + ->setAllowedTypes('channel', ['string', EuropeanChannelAwareInterface::class]) ->setNormalizer('channel', LazyOption::findOneBy($this->channelRepository, 'code')) ->setAllowedTypes('base_country', ['string', CountryInterface::class]) ->setNormalizer('base_country', LazyOption::findOneBy($this->countryRepository, 'code'))