Skip to content

Commit

Permalink
Fix PHPStan on PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Apr 29, 2024
1 parent d400f25 commit aefb6c1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 39 deletions.
14 changes: 3 additions & 11 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\./'
9 changes: 6 additions & 3 deletions src/Checker/ChannelEligibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/Checker/DefaultEligibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8, Symfony ^5.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8, Symfony ^5.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)

Check failure on line 24 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

MixedAssignment

src/Checker/DefaultEligibilityChecker.php:24:37: MixedAssignment: Unable to determine the type that $checker is being assigned to (see https://psalm.dev/032)
if (false === $checker->check($taxationAddress, $channel)) {

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8, Symfony ^5.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8, Symfony ^5.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)

Check failure on line 25 in src/Checker/DefaultEligibilityChecker.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

MixedMethodCall

src/Checker/DefaultEligibilityChecker.php:25:37: MixedMethodCall: Cannot determine the type of $checker when calling method check (see https://psalm.dev/015)
Expand Down
9 changes: 6 additions & 3 deletions src/Checker/SameBaseCountryEligibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Checker/VatNumberEligibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/Checker/VatRateEligibilityCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Fixture/Factory/AddressExampleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class AddressExampleFactory extends BaseAddressExampleFactory
{
/**
* @param FactoryInterface<AddressInterface&VATNumberAwareInterface> $addressFactory
* @param FactoryInterface<AddressInterface> $addressFactory
* @param RepositoryInterface<CountryInterface> $countryRepository
* @param RepositoryInterface<CustomerInterface> $customerRepository
*/
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 3 additions & 9 deletions src/Fixture/Factory/EuropeanChannelExampleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,9 +20,6 @@ class EuropeanChannelExampleFactory extends AbstractExampleFactory
private OptionsResolver $optionsResolver;

public function __construct(

Check failure on line 22 in src/Fixture/Factory/EuropeanChannelExampleFactory.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

Method FluxSE\SyliusEUVatPlugin\Fixture\Factory\EuropeanChannelExampleFactory::__construct() has parameter $channelRepository with generic interface Sylius\Component\Channel\Repository\ChannelRepositoryInterface but does not specify its types: T

Check failure on line 22 in src/Fixture/Factory/EuropeanChannelExampleFactory.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

Method FluxSE\SyliusEUVatPlugin\Fixture\Factory\EuropeanChannelExampleFactory::__construct() has parameter $channelRepository with generic interface Sylius\Component\Channel\Repository\ChannelRepositoryInterface but does not specify its types: T

Check failure on line 22 in src/Fixture/Factory/EuropeanChannelExampleFactory.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^6.4)

Method FluxSE\SyliusEUVatPlugin\Fixture\Factory\EuropeanChannelExampleFactory::__construct() has parameter $channelRepository with generic interface Sylius\Component\Channel\Repository\ChannelRepositoryInterface but does not specify its types: T

Check failure on line 22 in src/Fixture/Factory/EuropeanChannelExampleFactory.php

View workflow job for this annotation

GitHub Actions / Static checks (PHP 8.3, Symfony ^5.4)

Method FluxSE\SyliusEUVatPlugin\Fixture\Factory\EuropeanChannelExampleFactory::__construct() has parameter $channelRepository with generic interface Sylius\Component\Channel\Repository\ChannelRepositoryInterface but does not specify its types: T
/**
* @var ChannelRepositoryInterface<ChannelInterface&EuropeanChannelAwareInterface>
*/
private ChannelRepositoryInterface $channelRepository,
/**
* @var RepositoryInterface<CountryInterface>
Expand All @@ -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);
Expand All @@ -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'))
Expand Down

0 comments on commit aefb6c1

Please sign in to comment.