From 18c888a6a9ea2ffe3f9610e15d1c90cc24639f3d Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Mon, 19 Sep 2022 12:17:44 +0200 Subject: [PATCH] Fix static checks on symfony 6 - continuation --- composer-require-checker.json | 3 +- psalm.xml | 16 ++++---- .../CatalogPromotionCreatedListener.php | 2 + .../CatalogPromotionEndedListener.php | 2 + .../CatalogPromotionUpdatedListener.php | 2 + .../Form/Type/ExchangeRateType.php | 1 - .../GenerateProductVariantsSubscriber.php | 6 --- .../Command/AbstractRoleCommand.php | 4 +- .../Bundle/UserBundle/Security/UserLogin.php | 1 + .../spec/Security/UserPasswordEncoderSpec.php | 41 +++++++++---------- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index 22300230c9..b6fe79b6b2 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -26,7 +26,8 @@ "HWI\\Bundle\\OAuthBundle\\Connect\\AccountConnectorInterface", "HWI\\Bundle\\OAuthBundle\\OAuth\\Response\\UserResponseInterface", "HWI\\Bundle\\OAuthBundle\\Security\\Core\\User\\OAuthAwareUserProviderInterface", - "League\\Flysystem\\FilesystemOperator" + "League\\Flysystem\\FilesystemOperator", + "Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface" ], "php-core-extensions" : [ "Core", diff --git a/psalm.xml b/psalm.xml index 57679bb569..60847bdd2b 100644 --- a/psalm.xml +++ b/psalm.xml @@ -90,10 +90,7 @@ - - - @@ -105,7 +102,6 @@ - @@ -117,7 +113,6 @@ - @@ -126,7 +121,6 @@ - @@ -162,6 +156,15 @@ + + + + + + + + + @@ -219,7 +222,6 @@ - diff --git a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionCreatedListener.php b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionCreatedListener.php index 6dca7e48f3..cd5a562826 100644 --- a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionCreatedListener.php +++ b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionCreatedListener.php @@ -16,6 +16,7 @@ namespace Sylius\Bundle\CoreBundle\CatalogPromotion\Listener; use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\CatalogPromotion\Command\UpdateCatalogPromotionState; use Sylius\Bundle\CoreBundle\CatalogPromotion\Processor\AllProductVariantsCatalogPromotionsProcessorInterface; +use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionCreated; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\MessageBusInterface; @@ -32,6 +33,7 @@ final class CatalogPromotionCreatedListener public function __invoke(CatalogPromotionCreated $event): void { + /** @var CatalogPromotionInterface|null $catalogPromotion */ $catalogPromotion = $this->catalogPromotionRepository->findOneBy(['code' => $event->code]); if (null === $catalogPromotion) { diff --git a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionEndedListener.php b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionEndedListener.php index 465311e83c..74f938b9d3 100644 --- a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionEndedListener.php +++ b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionEndedListener.php @@ -16,6 +16,7 @@ namespace Sylius\Bundle\CoreBundle\CatalogPromotion\Listener; use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\CatalogPromotion\Command\UpdateCatalogPromotionState; use Sylius\Bundle\CoreBundle\CatalogPromotion\Processor\AllProductVariantsCatalogPromotionsProcessorInterface; +use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionEnded; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\MessageBusInterface; @@ -32,6 +33,7 @@ final class CatalogPromotionEndedListener public function __invoke(CatalogPromotionEnded $event): void { + /** @var CatalogPromotionInterface|null $catalogPromotion */ $catalogPromotion = $this->catalogPromotionRepository->findOneBy(['code' => $event->code]); if (null === $catalogPromotion) { diff --git a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionUpdatedListener.php b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionUpdatedListener.php index c0e4e120de..9239419951 100644 --- a/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionUpdatedListener.php +++ b/src/Sylius/Bundle/CoreBundle/CatalogPromotion/Listener/CatalogPromotionUpdatedListener.php @@ -16,6 +16,7 @@ namespace Sylius\Bundle\CoreBundle\CatalogPromotion\Listener; use Doctrine\ORM\EntityManagerInterface; use Sylius\Bundle\CoreBundle\CatalogPromotion\Command\UpdateCatalogPromotionState; use Sylius\Bundle\CoreBundle\CatalogPromotion\Processor\AllProductVariantsCatalogPromotionsProcessorInterface; +use Sylius\Component\Core\Model\CatalogPromotionInterface; use Sylius\Component\Promotion\Event\CatalogPromotionUpdated; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Messenger\MessageBusInterface; @@ -32,6 +33,7 @@ final class CatalogPromotionUpdatedListener public function __invoke(CatalogPromotionUpdated $event): void { + /** @var CatalogPromotionInterface|null $catalogPromotion */ $catalogPromotion = $this->catalogPromotionRepository->findOneBy(['code' => $event->code]); if (null === $catalogPromotion) { diff --git a/src/Sylius/Bundle/CurrencyBundle/Form/Type/ExchangeRateType.php b/src/Sylius/Bundle/CurrencyBundle/Form/Type/ExchangeRateType.php index ed3d041bab..6c33644a4a 100644 --- a/src/Sylius/Bundle/CurrencyBundle/Form/Type/ExchangeRateType.php +++ b/src/Sylius/Bundle/CurrencyBundle/Form/Type/ExchangeRateType.php @@ -64,7 +64,6 @@ final class ExchangeRateType extends AbstractResourceType { parent::configureOptions($resolver); - /** @psalm-suppress DeprecatedConstant */ $resolver->setDefault('rounding_mode', \NumberFormatter::ROUND_HALFEVEN); } diff --git a/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/GenerateProductVariantsSubscriber.php b/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/GenerateProductVariantsSubscriber.php index f791d2ab13..35a3955b1d 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/GenerateProductVariantsSubscriber.php +++ b/src/Sylius/Bundle/ProductBundle/Form/EventSubscriber/GenerateProductVariantsSubscriber.php @@ -52,12 +52,6 @@ final class GenerateProductVariantsSubscriber implements EventSubscriberInterfac try { $this->generator->generate($product); } catch (VariantWithNoOptionsValuesException $exception) { - if ($this->requestStackOrSession instanceof SessionInterface) { - $session = $this->requestStackOrSession; - } else { - $session = $this->requestStackOrSession->getSession(); - } - $this->getFlashBag()->add('error', $exception->getMessage()); } } diff --git a/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php b/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php index 71f749ba58..28aa0f369a 100644 --- a/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php +++ b/src/Sylius/Bundle/UserBundle/Command/AbstractRoleCommand.php @@ -60,7 +60,7 @@ abstract class AbstractRoleCommand extends ContainerAwareCommand if (!$input->getArgument('roles')) { $question = new Question('Please enter user\'s roles (separated by space):'); $question->setValidator(function (?string $roles) { - if (strlen($roles) < 1) { + if ('' === $roles) { throw new \RuntimeException('The value cannot be blank.'); } @@ -137,7 +137,7 @@ abstract class AbstractRoleCommand extends ContainerAwareCommand */ protected function getUserModelClass(string $userType): string { - $config = $this->getContainer()->getParameter('sylius.user.users'); + $config = (array) $this->getContainer()->getParameter('sylius.user.users'); if (empty($config[$userType]['user']['classes']['model'])) { throw new \InvalidArgumentException(sprintf('User type %s misconfigured.', $userType)); } diff --git a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php index 83efadabe9..82882e0b26 100644 --- a/src/Sylius/Bundle/UserBundle/Security/UserLogin.php +++ b/src/Sylius/Bundle/UserBundle/Security/UserLogin.php @@ -58,6 +58,7 @@ class UserLogin implements UserLoginInterface ); } + /** @psalm-suppress NullArgument */ return new UsernamePasswordToken( $user, null, diff --git a/src/Sylius/Bundle/UserBundle/spec/Security/UserPasswordEncoderSpec.php b/src/Sylius/Bundle/UserBundle/spec/Security/UserPasswordEncoderSpec.php index 382c70931d..950e0817bc 100644 --- a/src/Sylius/Bundle/UserBundle/spec/Security/UserPasswordEncoderSpec.php +++ b/src/Sylius/Bundle/UserBundle/spec/Security/UserPasswordEncoderSpec.php @@ -16,34 +16,31 @@ namespace spec\Sylius\Bundle\UserBundle\Security; use PhpSpec\ObjectBehavior; use Sylius\Component\User\Model\CredentialsHolderInterface; use Sylius\Component\User\Security\UserPasswordEncoderInterface; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; -if (Kernel::MAJOR_VERSION === 5) { - final class UserPasswordEncoderSpec extends ObjectBehavior +final class UserPasswordEncoderSpec extends ObjectBehavior +{ + function let(EncoderFactoryInterface $encoderFactory): void { - function let(EncoderFactoryInterface $encoderFactory): void - { - $this->beConstructedWith($encoderFactory); - } + $this->beConstructedWith($encoderFactory); + } - function it_implements_password_updater_interface(): void - { - $this->shouldImplement(UserPasswordEncoderInterface::class); - } + function it_implements_password_updater_interface(): void + { + $this->shouldImplement(UserPasswordEncoderInterface::class); + } - function it_encodes_password( - EncoderFactoryInterface $encoderFactory, - PasswordEncoderInterface $passwordEncoder, - CredentialsHolderInterface $user, - ): void { - $user->getPlainPassword()->willReturn('topSecretPlainPassword'); - $user->getSalt()->willReturn('typicalSalt'); - $encoderFactory->getEncoder($user->getWrappedObject())->willReturn($passwordEncoder); - $passwordEncoder->encodePassword('topSecretPlainPassword', 'typicalSalt')->willReturn('topSecretEncodedPassword'); + function it_encodes_password( + EncoderFactoryInterface $encoderFactory, + PasswordEncoderInterface $passwordEncoder, + CredentialsHolderInterface $user, + ): void { + $user->getPlainPassword()->willReturn('topSecretPlainPassword'); + $user->getSalt()->willReturn('typicalSalt'); + $encoderFactory->getEncoder($user->getWrappedObject())->willReturn($passwordEncoder); + $passwordEncoder->encodePassword('topSecretPlainPassword', 'typicalSalt')->willReturn('topSecretEncodedPassword'); - $this->encode($user)->shouldReturn('topSecretEncodedPassword'); - } + $this->encode($user)->shouldReturn('topSecretEncodedPassword'); } }