diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f60849a..f562dc17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -153,6 +153,10 @@ jobs: name: Run PHPStan run: vendor/bin/phpstan analyse -c phpstan.neon -l 6 src/ + - + name: Run ECS + run: vendor/bin/ecs check src + - name: Run Psalm run: vendor/bin/psalm diff --git a/.gitignore b/.gitignore index 3a1c4f4c..f486a1fb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,3 @@ /behat.yml /phpspec.yml /phpunit.xml - -ecs.php diff --git a/composer.json b/composer.json index b0899912..0629dd00 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "require-dev": { "behat/behat": "^3.6.1", "behat/mink-selenium2-driver": "^1.4", + "bitbag/coding-standard": "^1.0.1", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -43,7 +44,6 @@ "polishsymfonycommunity/symfony-mocker-container": "^1.0", "psalm/plugin-symfony": "^2.3", "sensiolabs/security-checker": "^6.0", - "sylius-labs/coding-standard": "^4.0", "symfony/browser-kit": "^4.4", "symfony/debug-bundle": "^4.4 || ^5.0", "symfony/dotenv": "^4.4 || ^5.0", diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..b088160e --- /dev/null +++ b/ecs.php @@ -0,0 +1,16 @@ +import('vendor/bitbag/coding-standard/ecs.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::PATHS, [ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); +}; diff --git a/src/BitBagSyliusAdyenPlugin.php b/src/BitBagSyliusAdyenPlugin.php index ef5db08d..0114c97f 100644 --- a/src/BitBagSyliusAdyenPlugin.php +++ b/src/BitBagSyliusAdyenPlugin.php @@ -12,7 +12,6 @@ use BitBag\SyliusAdyenPlugin\DependencyInjection\CompilerPass\AuthenticationManagerPolyfillPass; use BitBag\SyliusAdyenPlugin\DependencyInjection\CompilerPass\MessageBusPolyfillPass; -use BitBag\SyliusAdyenPlugin\DependencyInjection\CompilerPass\SyliusBehatPolyfillCompilerPass; use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -27,7 +26,7 @@ public function getContainerExtension(): ?ExtensionInterface { $this->containerExtension = $this->createContainerExtension() ?? false; - return $this->containerExtension !== false ? $this->containerExtension : null; + return false !== $this->containerExtension ? $this->containerExtension : null; } public function build(ContainerBuilder $container): void diff --git a/src/Bus/Command/CreateReferenceForRefund.php b/src/Bus/Command/CreateReferenceForRefund.php index 0a356915..e61af010 100644 --- a/src/Bus/Command/CreateReferenceForRefund.php +++ b/src/Bus/Command/CreateReferenceForRefund.php @@ -25,8 +25,11 @@ final class CreateReferenceForRefund /** @var string */ private $refundReference; - public function __construct(string $refundReference, RefundPaymentInterface $refundPayment, PaymentInterface $payment) - { + public function __construct( + string $refundReference, + RefundPaymentInterface $refundPayment, + PaymentInterface $payment + ) { $details = $payment->getDetails(); Assert::keyExists($details, 'pspReference', 'Payment pspReference is not present'); diff --git a/src/Bus/Handler/AlterPaymentHandler.php b/src/Bus/Handler/AlterPaymentHandler.php index 5442c07f..28aef668 100644 --- a/src/Bus/Handler/AlterPaymentHandler.php +++ b/src/Bus/Handler/AlterPaymentHandler.php @@ -36,7 +36,7 @@ public function __construct(AdyenClientProviderInterface $adyenClientProvider) private function isCompleted(OrderInterface $order): bool { - return $order->getPaymentState() === PaymentInterface::STATE_COMPLETED; + return PaymentInterface::STATE_COMPLETED === $order->getPaymentState(); } private function isAdyenPayment(PaymentInterface $payment): bool @@ -46,8 +46,8 @@ private function isAdyenPayment(PaymentInterface $payment): bool */ $method = $payment->getMethod(); if ( - $method === null - || $method->getGatewayConfig() === null + null === $method + || null === $method->getGatewayConfig() || !isset($this->getGatewayConfig($method)->getConfig()[AdyenClientProviderInterface::FACTORY_NAME]) ) { return false; @@ -63,7 +63,7 @@ private function getPayment(OrderInterface $order): ?PaymentInterface } $payment = $order->getLastPayment(PaymentInterface::STATE_AUTHORIZED); - if ($payment === null) { + if (null === $payment) { return null; } @@ -90,7 +90,7 @@ public function __invoke(AlterPaymentCommand $alterPaymentCommand): void { $payment = $this->getPayment($alterPaymentCommand->getOrder()); - if ($payment === null || !$this->isAdyenPayment($payment)) { + if (null === $payment || !$this->isAdyenPayment($payment)) { return; } diff --git a/src/Bus/Handler/CreateReferenceForPaymentHandler.php b/src/Bus/Handler/CreateReferenceForPaymentHandler.php index 88359078..598383ae 100644 --- a/src/Bus/Handler/CreateReferenceForPaymentHandler.php +++ b/src/Bus/Handler/CreateReferenceForPaymentHandler.php @@ -59,7 +59,7 @@ public function __invoke(CreateReferenceForPayment $referenceCommand): void $object = $this->adyenReferenceFactory->createForPayment($referenceCommand->getPayment()); $existing = $this->getExisting($object); - if ($existing !== null) { + if (null !== $existing) { $existing->touch(); $object = $existing; } diff --git a/src/Bus/Handler/GetTokenHandler.php b/src/Bus/Handler/GetTokenHandler.php index be8e45f9..d158eaf1 100644 --- a/src/Bus/Handler/GetTokenHandler.php +++ b/src/Bus/Handler/GetTokenHandler.php @@ -47,7 +47,7 @@ private function getUser(): ?UserInterface { $token = $this->tokenStorage->getToken(); - if ($token === null) { + if (null === $token) { return null; } @@ -62,12 +62,12 @@ private function getUser(): ?UserInterface */ public function __invoke(GetToken $getTokenQuery): ?AdyenTokenInterface { - if ($this->getUser() === null) { + if (null === $this->getUser()) { return null; } $customer = $getTokenQuery->getOrder()->getCustomer(); - if ($customer === null) { + if (null === $customer) { throw new OrderWithoutCustomerException($getTokenQuery->getOrder()); } @@ -82,7 +82,7 @@ public function __invoke(GetToken $getTokenQuery): ?AdyenTokenInterface $customer ); - if ($token !== null) { + if (null !== $token) { return $token; } diff --git a/src/Bus/Handler/PaymentFinalizationHandler.php b/src/Bus/Handler/PaymentFinalizationHandler.php index 0cc52a0c..6431ae86 100644 --- a/src/Bus/Handler/PaymentFinalizationHandler.php +++ b/src/Bus/Handler/PaymentFinalizationHandler.php @@ -46,7 +46,7 @@ private function updatePaymentState(PaymentInterface $payment, string $transitio private function updatePayment(PaymentInterface $payment): void { $order = $payment->getOrder(); - if ($order === null) { + if (null === $order) { return; } @@ -67,6 +67,6 @@ public function __invoke(PaymentFinalizationCommand $command): void private function isAccepted(PaymentInterface $payment): bool { - return $this->getOrderFromPayment($payment)->getPaymentState() !== OrderPaymentStates::STATE_PAID; + return OrderPaymentStates::STATE_PAID !== $this->getOrderFromPayment($payment)->getPaymentState(); } } diff --git a/src/Bus/Handler/RefundPaymentGeneratedHandler.php b/src/Bus/Handler/RefundPaymentGeneratedHandler.php index 90bde81c..c49cf1e8 100644 --- a/src/Bus/Handler/RefundPaymentGeneratedHandler.php +++ b/src/Bus/Handler/RefundPaymentGeneratedHandler.php @@ -62,7 +62,7 @@ private function createReference( PaymentInterface $payment ): void { $refund = $this->refundPaymentRepository->find($refundPaymentGenerated->id()); - if ($refund === null) { + if (null === $refund) { return; } @@ -97,8 +97,8 @@ public function __invoke(RefundPaymentGenerated $refundPaymentGenerated): void $payment = $this->paymentRepository->find($refundPaymentGenerated->paymentId()); $paymentMethod = $this->paymentMethodRepository->find($refundPaymentGenerated->paymentMethodId()); - if ($payment === null - || $paymentMethod === null + if (null === $payment + || null === $paymentMethod || !isset($this->getGatewayConfig($paymentMethod)->getConfig()[AdyenClientProviderInterface::FACTORY_NAME]) ) { return; diff --git a/src/Bus/Handler/TakeOverPaymentHandler.php b/src/Bus/Handler/TakeOverPaymentHandler.php index e2d23753..c668d34e 100644 --- a/src/Bus/Handler/TakeOverPaymentHandler.php +++ b/src/Bus/Handler/TakeOverPaymentHandler.php @@ -21,6 +21,7 @@ final class TakeOverPaymentHandler implements MessageHandlerInterface { use PayableOrderPaymentTrait; + use PaymentFromOrderTrait; /** @var PaymentMethodRepositoryInterface */ diff --git a/src/Bus/PaymentCommandFactory.php b/src/Bus/PaymentCommandFactory.php index 5222ec0a..0a371933 100644 --- a/src/Bus/PaymentCommandFactory.php +++ b/src/Bus/PaymentCommandFactory.php @@ -52,7 +52,7 @@ public function createForEvent( PaymentInterface $payment, ?NotificationItemData $notificationItemData = null ): PaymentLifecycleCommand { - if ($notificationItemData !== null) { + if (null !== $notificationItemData) { $event = $this->eventCodeResolver->resolve($notificationItemData); } diff --git a/src/Bus/PaymentCommandFactoryInterface.php b/src/Bus/PaymentCommandFactoryInterface.php index e65d653f..c7b6f21e 100644 --- a/src/Bus/PaymentCommandFactoryInterface.php +++ b/src/Bus/PaymentCommandFactoryInterface.php @@ -32,5 +32,9 @@ interface PaymentCommandFactoryInterface 'cancellation' => PaymentCancelledCommand::class, ]; - public function createForEvent(string $event, PaymentInterface $payment, ?NotificationItemData $notificationItemData = null): PaymentLifecycleCommand; + public function createForEvent( + string $event, + PaymentInterface $payment, + ?NotificationItemData $notificationItemData = null + ): PaymentLifecycleCommand; } diff --git a/src/Callback/PreserveOrderTokenUponRedirectionCallback.php b/src/Callback/PreserveOrderTokenUponRedirectionCallback.php index ede6eef8..c8f666a6 100644 --- a/src/Callback/PreserveOrderTokenUponRedirectionCallback.php +++ b/src/Callback/PreserveOrderTokenUponRedirectionCallback.php @@ -29,7 +29,7 @@ public function __invoke(OrderInterface $order): void { $tokenValue = $order->getTokenValue(); - if ($tokenValue === null) { + if (null === $tokenValue) { return; } diff --git a/src/Client/AdyenTransportFactory.php b/src/Client/AdyenTransportFactory.php index 7c1a4e41..139f9e0b 100644 --- a/src/Client/AdyenTransportFactory.php +++ b/src/Client/AdyenTransportFactory.php @@ -40,13 +40,13 @@ public function create(array $options): Client $client = new Client(); $client->setHttpClient($this->adyenHttpClient); - if ($this->logger !== null) { + if (null !== $this->logger) { $client->setLogger($this->logger); } $client->setXApiKey($options['apiKey']); $client->setEnvironment( - $options['environment'] == AdyenClientInterface::TEST_ENVIRONMENT + AdyenClientInterface::TEST_ENVIRONMENT == $options['environment'] ? Environment::TEST : Environment::LIVE ); diff --git a/src/Client/ClientPayloadFactory.php b/src/Client/ClientPayloadFactory.php index 3c7225ad..b08a04e6 100644 --- a/src/Client/ClientPayloadFactory.php +++ b/src/Client/ClientPayloadFactory.php @@ -77,9 +77,9 @@ public function createForAvailablePaymentMethods( ?AdyenTokenInterface $adyenToken = null ): array { $address = $order->getBillingAddress(); - $countryCode = $address !== null ? (string) $address->getCountryCode() : ''; + $countryCode = null !== $address ? (string) $address->getCountryCode() : ''; $request = $this->requestStack->getCurrentRequest(); - $locale = $request !== null ? $request->getLocale() : ''; + $locale = null !== $request ? $request->getLocale() : ''; $payload = [ 'amount' => [ @@ -119,7 +119,7 @@ public function createForSubmitPayment( ?AdyenTokenInterface $adyenToken = null ): array { $billingAddress = $order->getBillingAddress(); - $countryCode = $billingAddress !== null + $countryCode = null !== $billingAddress ? (string) $billingAddress->getCountryCode() : null ; @@ -263,13 +263,13 @@ private function getOrigin(string $url): string private function isTokenizationSupported(array $payload, ?AdyenTokenInterface $customerIdentifier): bool { - if ($customerIdentifier === null) { + if (null === $customerIdentifier) { return false; } if ( isset($payload['paymentMethod']['type']) - && $payload['paymentMethod']['type'] !== AdyenClientInterface::CREDIT_CARD_TYPE + && AdyenClientInterface::CREDIT_CARD_TYPE !== $payload['paymentMethod']['type'] ) { return false; } @@ -281,7 +281,7 @@ private function injectShopperReference( array $payload, ?AdyenTokenInterface $customerIdentifier ): array { - if ($customerIdentifier !== null) { + if (null !== $customerIdentifier) { $payload['shopperReference'] = $customerIdentifier->getIdentifier(); } @@ -292,7 +292,7 @@ private function add3DSecureFlags(array $receivedPayload, array $payload): array { if ( isset($receivedPayload['paymentMethod']['type']) - && $receivedPayload['paymentMethod']['type'] == 'scheme' + && 'scheme' == $receivedPayload['paymentMethod']['type'] ) { $payload['additionalData'] = [ 'allow3DS2' => true, diff --git a/src/Client/ClientPayloadFactoryInterface.php b/src/Client/ClientPayloadFactoryInterface.php index 3f6a1f2a..7839ac9c 100644 --- a/src/Client/ClientPayloadFactoryInterface.php +++ b/src/Client/ClientPayloadFactoryInterface.php @@ -20,17 +20,31 @@ interface ClientPayloadFactoryInterface { public const NO_COUNTRY_AVAILABLE_PLACEHOLDER = 'ZZ'; - public function createForAvailablePaymentMethods(ArrayObject $options, OrderInterface $order, ?AdyenTokenInterface $adyenToken = null): array; + public function createForAvailablePaymentMethods( + ArrayObject $options, + OrderInterface $order, + ?AdyenTokenInterface $adyenToken = null + ): array; public function createForPaymentDetails(array $receivedPayload, ?AdyenTokenInterface $adyenToken = null): array; - public function createForSubmitPayment(ArrayObject $options, string $url, array $receivedPayload, OrderInterface $order, ?AdyenTokenInterface $adyenToken = null): array; + public function createForSubmitPayment( + ArrayObject $options, + string $url, + array $receivedPayload, + OrderInterface $order, + ?AdyenTokenInterface $adyenToken = null + ): array; public function createForCapture(ArrayObject $options, PaymentInterface $payment): array; public function createForCancel(ArrayObject $options, PaymentInterface $payment): array; - public function createForTokenRemove(ArrayObject $options, string $paymentReference, AdyenTokenInterface $adyenToken): array; + public function createForTokenRemove( + ArrayObject $options, + string $paymentReference, + AdyenTokenInterface $adyenToken + ): array; public function createForRefund( ArrayObject $options, diff --git a/src/Client/PaymentMethodsFilter.php b/src/Client/PaymentMethodsFilter.php index 9c4d00e7..b5b681c1 100644 --- a/src/Client/PaymentMethodsFilter.php +++ b/src/Client/PaymentMethodsFilter.php @@ -37,7 +37,7 @@ public function filter(array $paymentMethodsResponse): array { Assert::keyExists($paymentMethodsResponse, 'paymentMethods'); - if (count((array) $this->supportedMethodsList) > 0) { + if (0 < count((array) $this->supportedMethodsList)) { $paymentMethodsResponse['paymentMethods'] = $this->doFilter( (array) $paymentMethodsResponse['paymentMethods'] ); diff --git a/src/Controller/Shop/DropinConfigurationAction.php b/src/Controller/Shop/DropinConfigurationAction.php index da5f62b2..09cf98fc 100644 --- a/src/Controller/Shop/DropinConfigurationAction.php +++ b/src/Controller/Shop/DropinConfigurationAction.php @@ -31,12 +31,16 @@ class DropinConfigurationAction /** @var CartContextInterface */ private $cartContext; + /** @var PaymentMethodsForOrderProvider */ private $paymentMethodsForOrderProvider; + /** @var UrlGeneratorInterface */ private $urlGenerator; + /** @var OrderRepositoryInterface */ private $orderRepository; + /** @var TranslatorInterface */ private $translator; @@ -54,11 +58,14 @@ public function __construct( $this->translator = $translator; } - public function __invoke(Request $request, string $code, ?string $orderToken = null): JsonResponse - { + public function __invoke( + Request $request, + string $code, + ?string $orderToken = null + ): JsonResponse { $order = $this->getOrder($orderToken); - if ($order === null || $order->getId() === null) { + if (null === $order || null === $order->getId()) { return $this->getResponseForDroppedOrder($request); } @@ -119,7 +126,7 @@ private function getOrder(?string $orderToken = null): ?OrderInterface * @var ?OrderInterface $result */ $result = - $orderToken !== null + null !== $orderToken ? $this->orderRepository->findOneByTokenValue($orderToken) : $this->cartContext->getCart() ; @@ -137,7 +144,7 @@ private function getResponseForDroppedOrder(Request $request): JsonResponse ); try { - if ($tokenValue === null) { + if (null === $tokenValue) { throw new NotFoundHttpException(); } } finally { diff --git a/src/Controller/Shop/PaymentDetailsAction.php b/src/Controller/Shop/PaymentDetailsAction.php index 50280976..88e79d48 100644 --- a/src/Controller/Shop/PaymentDetailsAction.php +++ b/src/Controller/Shop/PaymentDetailsAction.php @@ -22,6 +22,7 @@ class PaymentDetailsAction { use PayableOrderPaymentTrait; + use PaymentFromOrderTrait; /** @var AdyenClientProviderInterface */ diff --git a/src/Controller/Shop/PaymentsAction.php b/src/Controller/Shop/PaymentsAction.php index 7fbd5110..c4e6c00d 100644 --- a/src/Controller/Shop/PaymentsAction.php +++ b/src/Controller/Shop/PaymentsAction.php @@ -29,6 +29,7 @@ class PaymentsAction { use PayableOrderPaymentTrait; + use PaymentFromOrderTrait; public const REDIRECT_TARGET_ACTION = 'bitbag_adyen_thank_you'; @@ -84,7 +85,7 @@ private function prepareOrder(Request $request, OrderInterface $order): void /** * @psalm-suppress InternalMethod */ - if ($request->get('tokenValue') === null) { + if (null === $request->get('tokenValue')) { $request->getSession()->set(self::ORDER_ID_KEY, $order->getId()); } @@ -96,7 +97,7 @@ public function __invoke(Request $request, ?string $code = null): JsonResponse $order = $this->paymentCheckoutOrderResolver->resolve(); $this->prepareOrder($request, $order); - if ($code !== null) { + if (null !== $code) { $this->dispatcher->dispatch(new TakeOverPayment($order, $code)); } diff --git a/src/Controller/Shop/RedirectTargetAction.php b/src/Controller/Shop/RedirectTargetAction.php index 93717a40..7f0d66d2 100644 --- a/src/Controller/Shop/RedirectTargetAction.php +++ b/src/Controller/Shop/RedirectTargetAction.php @@ -46,7 +46,7 @@ private function retrieveCurrentPayment(string $code, Request $request): ?Paymen { $referenceId = $this->getReferenceId($request); - if ($referenceId !== null) { + if (null !== $referenceId) { return $this->paymentDetailsResolver->resolve($code, $referenceId); } diff --git a/src/Controller/Shop/RemoveStoredTokenAction.php b/src/Controller/Shop/RemoveStoredTokenAction.php index 7f01500a..caf258e2 100644 --- a/src/Controller/Shop/RemoveStoredTokenAction.php +++ b/src/Controller/Shop/RemoveStoredTokenAction.php @@ -49,7 +49,7 @@ public function __construct( private function getUser(): ShopUserInterface { $token = $this->tokenStorage->getToken(); - if ($token === null) { + if (null === $token) { throw TokenRemovalFailureException::forAnonymous(); } @@ -61,20 +61,23 @@ private function getUser(): ShopUserInterface return $user; } - public function __invoke(string $code, string $paymentReference, Request $request): Response - { + public function __invoke( + string $code, + string $paymentReference, + Request $request + ): Response { /** * @var ?CustomerInterface $customer */ $customer = $this->getUser()->getCustomer(); - if ($customer === null) { + if (null === $customer) { throw TokenRemovalFailureException::forAnonymous(); } $paymentMethod = $this->paymentMethodRepository->getOneForAdyenAndCode($code); $token = $this->adyenTokenRepository->findOneByPaymentMethodAndCustomer($paymentMethod, $customer); - if ($token === null) { + if (null === $token) { throw TokenRemovalFailureException::forNonExistingToken(); } diff --git a/src/DependencyInjection/BitBagSyliusAdyenExtension.php b/src/DependencyInjection/BitBagSyliusAdyenExtension.php index 7370b3db..99845811 100644 --- a/src/DependencyInjection/BitBagSyliusAdyenExtension.php +++ b/src/DependencyInjection/BitBagSyliusAdyenExtension.php @@ -20,6 +20,7 @@ final class BitBagSyliusAdyenExtension extends ConfigurableExtension implements PrependExtensionInterface { public const TRANSPORT_FACTORY_ID = 'bitbag.sylius_adyen_plugin.client.adyen_transport_factory'; + public const SUPPORTED_PAYMENT_METHODS_LIST = 'bitbag.sylius_adyen_plugin.supported_payment_methods'; public function prepend(ContainerBuilder $container): void @@ -44,7 +45,7 @@ public function loadInternal(array $config, ContainerBuilder $container): void $container->setParameter(self::SUPPORTED_PAYMENT_METHODS_LIST, (array) $config['supported_types']); - if ($config['logger'] !== null) { + if (null !== $config['logger']) { $container->setAlias('bitbag.sylius_adyen_plugin.logger', (string) $config['logger']); } diff --git a/src/DependencyInjection/CompilerPass/AuthenticationManagerPolyfillPass.php b/src/DependencyInjection/CompilerPass/AuthenticationManagerPolyfillPass.php index 06d828b1..aa2a7c11 100644 --- a/src/DependencyInjection/CompilerPass/AuthenticationManagerPolyfillPass.php +++ b/src/DependencyInjection/CompilerPass/AuthenticationManagerPolyfillPass.php @@ -18,9 +18,9 @@ class AuthenticationManagerPolyfillPass implements CompilerPassInterface public function process(ContainerBuilder $container): void { if ( - $container->has('security.authentication_manager') === false + false === $container->has('security.authentication_manager') && - $container->has('security.authentication.manager') === true + true === $container->has('security.authentication.manager') ) { $container->setAlias('security.authentication_manager', 'security.authentication.manager'); } diff --git a/src/DependencyInjection/CompilerPass/MessageBusPolyfillPass.php b/src/DependencyInjection/CompilerPass/MessageBusPolyfillPass.php index 647deca3..16b9826f 100644 --- a/src/DependencyInjection/CompilerPass/MessageBusPolyfillPass.php +++ b/src/DependencyInjection/CompilerPass/MessageBusPolyfillPass.php @@ -19,6 +19,7 @@ class MessageBusPolyfillPass implements CompilerPassInterface 'sylius.command_bus' => 'sylius_default.bus', 'sylius.event_bus' => 'sylius_event.bus', ]; + public const COMMAND_BUS_TAG = 'bitbag.sylius_adyen_plugin.command_bus'; private function setupDefaultCommandBus(array $buses, ContainerBuilder $container): void diff --git a/src/Entity/Log.php b/src/Entity/Log.php index 60990b49..7e4feec2 100644 --- a/src/Entity/Log.php +++ b/src/Entity/Log.php @@ -1,4 +1,6 @@ -paymentMethodRepository->findOneForAdyenAndCode($code); - if ($paymentMethod === null) { + if (null === $paymentMethod) { throw new NotFoundHttpException(); } @@ -89,7 +89,7 @@ private function isAuthenticated(Request $request, array $configuration): bool public function filterAuthentication(RequestEvent $requestEvent): void { $request = $requestEvent->getRequest(); - if ($request->attributes->get('_route') !== self::ROUTE_NAME) { + if (self::ROUTE_NAME !== $request->attributes->get('_route')) { return; } diff --git a/src/EventSubscriber/FilterManualRefundConfirmationSubscriber.php b/src/EventSubscriber/FilterManualRefundConfirmationSubscriber.php index 1c3df78e..2ea935f6 100644 --- a/src/EventSubscriber/FilterManualRefundConfirmationSubscriber.php +++ b/src/EventSubscriber/FilterManualRefundConfirmationSubscriber.php @@ -31,8 +31,8 @@ public static function getSubscribedEvents(): array public function filter(TransitionEvent $event): void { if ( - $event->getStateMachine()->getGraph() !== RefundPaymentTransitions::GRAPH - || $event->getTransition() !== RefundPaymentTransitions::TRANSITION_COMPLETE + RefundPaymentTransitions::GRAPH !== $event->getStateMachine()->getGraph() + || RefundPaymentTransitions::TRANSITION_COMPLETE !== $event->getTransition() ) { return; } diff --git a/src/EventSubscriber/RoutePaymentCompleteTransitionSubscriber.php b/src/EventSubscriber/RoutePaymentCompleteTransitionSubscriber.php index fc1eed2f..28af606c 100644 --- a/src/EventSubscriber/RoutePaymentCompleteTransitionSubscriber.php +++ b/src/EventSubscriber/RoutePaymentCompleteTransitionSubscriber.php @@ -43,11 +43,11 @@ public static function getSubscribedEvents(): array private function isProcessableAdyenPayment(TransitionEvent $event): bool { - if ($event->getStateMachine()->getGraph() !== PaymentTransitions::GRAPH) { + if (PaymentTransitions::GRAPH !== $event->getStateMachine()->getGraph()) { return false; } - if ($event->getTransition() !== PaymentTransitions::TRANSITION_COMPLETE) { + if (PaymentTransitions::TRANSITION_COMPLETE !== $event->getTransition()) { return false; } if (!isset($this->getObject($event)->getDetails()['pspReference'])) { @@ -63,7 +63,7 @@ private function getObject(TransitionEvent $event): PaymentInterface * @var ?PaymentInterface $object */ $object = $event->getStateMachine()->getObject(); - if ($object === null) { + if (null === $object) { throw new UnprocessablePaymentException(); } @@ -74,8 +74,8 @@ public function canComplete(TransitionEvent $event): void { if ( !$this->isProcessableAdyenPayment($event) - || $event->getState() !== PaymentInterface::STATE_PROCESSING - || $event->getTransition() === PaymentTransitions::TRANSITION_CAPTURE + || PaymentInterface::STATE_PROCESSING !== $event->getState() + || PaymentTransitions::TRANSITION_CAPTURE === $event->getTransition() ) { return; } diff --git a/src/Factory/LogFactory.php b/src/Factory/LogFactory.php index 9247a2f9..e3a27e4a 100644 --- a/src/Factory/LogFactory.php +++ b/src/Factory/LogFactory.php @@ -22,8 +22,11 @@ public function createNew() return $this->factory->createNew(); } - public function create(string $message, int $level, int $errorCode): LogInterface - { + public function create( + string $message, + int $level, + int $errorCode + ): LogInterface { /** @var LogInterface $log */ $log = $this->createNew(); diff --git a/src/Factory/LogFactoryInterface.php b/src/Factory/LogFactoryInterface.php index 4630a8c1..3b624e96 100644 --- a/src/Factory/LogFactoryInterface.php +++ b/src/Factory/LogFactoryInterface.php @@ -8,5 +8,9 @@ interface LogFactoryInterface { - public function create(string $message, int $level, int $errorCode): LogInterface; + public function create( + string $message, + int $level, + int $errorCode + ): LogInterface; } diff --git a/src/Form/Type/CredentialType.php b/src/Form/Type/CredentialType.php index 9881a66b..e5a0c20f 100644 --- a/src/Form/Type/CredentialType.php +++ b/src/Form/Type/CredentialType.php @@ -21,9 +21,12 @@ final class CredentialType extends PasswordType { public const CREDENTIAL_PLACEHOLDER = '#CREDENTIAL_PLACEHOLDER#'; - public function buildView(FormView $view, FormInterface $form, array $options): void - { - if (strlen((string) $view->vars['value']) === 0 || $form->isSubmitted()) { + public function buildView( + FormView $view, + FormInterface $form, + array $options + ): void { + if (0 === strlen((string) $view->vars['value']) || $form->isSubmitted()) { return; } @@ -35,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->addEventListener( FormEvents::SUBMIT, function (SubmitEvent $event): void { - if ($event->getData() !== self::CREDENTIAL_PLACEHOLDER) { + if (self::CREDENTIAL_PLACEHOLDER !== $event->getData()) { return; } diff --git a/src/Form/Type/LoggerLevelFilterType.php b/src/Form/Type/LoggerLevelFilterType.php index b63a9fe3..87ca9a4a 100644 --- a/src/Form/Type/LoggerLevelFilterType.php +++ b/src/Form/Type/LoggerLevelFilterType.php @@ -1,4 +1,6 @@ -vars['environment'] = $options['environment']; $view->vars['payment_methods'] = $options['payment_methods']; diff --git a/src/Grid/Filter/LoggerLevel.php b/src/Grid/Filter/LoggerLevel.php index a4735819..2156809e 100644 --- a/src/Grid/Filter/LoggerLevel.php +++ b/src/Grid/Filter/LoggerLevel.php @@ -1,4 +1,6 @@ -restrict($dataSource->getExpressionBuilder()->equals('level', $data['loggerLevel'])); } diff --git a/src/Logging/Monolog/DoctrineHandler.php b/src/Logging/Monolog/DoctrineHandler.php index e96ea6fa..2e58880f 100644 --- a/src/Logging/Monolog/DoctrineHandler.php +++ b/src/Logging/Monolog/DoctrineHandler.php @@ -1,4 +1,6 @@ -getCustomer(); diff --git a/src/Normalizer/AddressNormalizer.php b/src/Normalizer/AddressNormalizer.php index 9ed19b2a..e753a198 100644 --- a/src/Normalizer/AddressNormalizer.php +++ b/src/Normalizer/AddressNormalizer.php @@ -17,9 +17,7 @@ final class AddressNormalizer extends AbstractPaymentNormalizer { - /** - * @var StreetAddressResolverInterface - */ + /** @var StreetAddressResolverInterface */ private $streetAddressResolver; public function __construct(StreetAddressResolverInterface $streetAddressResolver) @@ -30,16 +28,22 @@ public function __construct(StreetAddressResolverInterface $streetAddressResolve /** * @param mixed|AddressInterface $data */ - public function supportsNormalization($data, string $format = null, array $context = []): bool - { + public function supportsNormalization( + $data, + string $format = null, + array $context = [] + ): bool { return parent::supportsNormalization($data, $format, $context) && $data instanceof AddressInterface; } /** * @param mixed $object */ - public function normalize($object, string $format = null, array $context = []): array - { + public function normalize( + $object, + string $format = null, + array $context = [] + ): array { Assert::isInstanceOf($object, AddressInterface::class); $address = [ diff --git a/src/Normalizer/OrderItemToLineItemNormalizer.php b/src/Normalizer/OrderItemToLineItemNormalizer.php index e5f6d566..c142c7eb 100644 --- a/src/Normalizer/OrderItemToLineItemNormalizer.php +++ b/src/Normalizer/OrderItemToLineItemNormalizer.php @@ -42,16 +42,22 @@ public function __construct( /** * @param mixed|OrderItemInterface $data */ - public function supportsNormalization($data, string $format = null, array $context = []): bool - { + public function supportsNormalization( + $data, + string $format = null, + array $context = [] + ): bool { return parent::supportsNormalization($data, $format, $context) && $data instanceof OrderItemInterface; } /** * @param mixed $object */ - public function normalize($object, string $format = null, array $context = []): array - { + public function normalize( + $object, + string $format = null, + array $context = [] + ): array { Assert::isInstanceOf($object, OrderItemInterface::class); $locale = $this->getLocale(); @@ -83,7 +89,7 @@ private function getLocale(): string { $request = $this->requestStack->getCurrentRequest(); - if ($request === null) { + if (null === $request) { return self::DEFAULT_DESCRIPTION_LOCALE; } diff --git a/src/Processor/PaymentResponseProcessor.php b/src/Processor/PaymentResponseProcessor.php index 28a78135..e5f155f7 100644 --- a/src/Processor/PaymentResponseProcessor.php +++ b/src/Processor/PaymentResponseProcessor.php @@ -36,8 +36,11 @@ public function __construct( $this->urlGenerator = $urlGenerator; } - private function processForPaymentSpecified(string $code, Request $request, PaymentInterface $payment): ?string - { + private function processForPaymentSpecified( + string $code, + Request $request, + PaymentInterface $payment + ): ?string { foreach ($this->processors as $processor) { if (!$processor->accepts($request, $payment)) { continue; @@ -49,14 +52,17 @@ private function processForPaymentSpecified(string $code, Request $request, Paym return null; } - public function process(string $code, Request $request, ?PaymentInterface $payment): string - { + public function process( + string $code, + Request $request, + ?PaymentInterface $payment + ): string { $result = null; - if ($payment !== null) { + if (null !== $payment) { $result = $this->processForPaymentSpecified($code, $request, $payment); } - if ($result !== null) { + if (null !== $result) { return $result; } diff --git a/src/Processor/PaymentResponseProcessor/AbstractProcessor.php b/src/Processor/PaymentResponseProcessor/AbstractProcessor.php index 44c0e095..80c4ff96 100644 --- a/src/Processor/PaymentResponseProcessor/AbstractProcessor.php +++ b/src/Processor/PaymentResponseProcessor/AbstractProcessor.php @@ -18,7 +18,9 @@ abstract class AbstractProcessor implements ProcessorInterface { public const PAYMENT_STATUS_RECEIVED_CODE = 'payment_status_received'; + public const FLASH_INFO = 'info'; + public const FLASH_ERROR = 'error'; /** @var TranslatorInterface|null */ @@ -26,7 +28,7 @@ abstract class AbstractProcessor implements ProcessorInterface protected function isResultCodeSupportedForPayment(?PaymentInterface $payment, array $resultCodes): bool { - if ($payment === null) { + if (null === $payment) { return false; } @@ -42,9 +44,12 @@ protected function isResultCodeSupportedForPayment(?PaymentInterface $payment, a ); } - protected function addFlash(Request $request, string $type, string $message): void - { - if ($this->translator !== null) { + protected function addFlash( + Request $request, + string $type, + string $message + ): void { + if (null !== $this->translator) { $message = $this->translator->trans($message); } diff --git a/src/Processor/PaymentResponseProcessor/FailedResponseProcessor.php b/src/Processor/PaymentResponseProcessor/FailedResponseProcessor.php index 01f41798..bb99bd82 100644 --- a/src/Processor/PaymentResponseProcessor/FailedResponseProcessor.php +++ b/src/Processor/PaymentResponseProcessor/FailedResponseProcessor.php @@ -55,7 +55,7 @@ private function getRedirectUrl(OrderInterface $order): string { $tokenValue = $order->getTokenValue(); - if ($tokenValue === null) { + if (null === $tokenValue) { return $this->urlGenerator->generate(self::CHECKOUT_FINALIZATION_REDIRECT); } @@ -65,8 +65,11 @@ private function getRedirectUrl(OrderInterface $order): string ); } - public function process(string $code, Request $request, PaymentInterface $payment): string - { + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string { $this->addFlash($request, self::FLASH_ERROR, self::LABEL_PAYMENT_FAILED); $this->dispatchPaymentStatusReceived($payment); diff --git a/src/Processor/PaymentResponseProcessor/FallbackResponseProcessor.php b/src/Processor/PaymentResponseProcessor/FallbackResponseProcessor.php index b151b731..ad5bbe48 100644 --- a/src/Processor/PaymentResponseProcessor/FallbackResponseProcessor.php +++ b/src/Processor/PaymentResponseProcessor/FallbackResponseProcessor.php @@ -28,13 +28,16 @@ public function __construct(UrlGeneratorInterface $urlGenerator) public function accepts(Request $request, ?PaymentInterface $payment): bool { - return $payment !== null; + return null !== $payment; } - public function process(string $code, Request $request, PaymentInterface $payment): string - { + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string { $tokenValue = $request->query->get('tokenValue'); - if ($tokenValue === null) { + if (null === $tokenValue) { $this->setActiveOrderViaPayment($request, $payment); } @@ -51,7 +54,7 @@ public function process(string $code, Request $request, PaymentInterface $paymen private function setActiveOrderViaPayment(Request $request, PaymentInterface $payment): void { $order = $payment->getOrder(); - if ($order === null) { + if (null === $order) { return; } diff --git a/src/Processor/PaymentResponseProcessor/PaymentProcessingResponseProcessor.php b/src/Processor/PaymentResponseProcessor/PaymentProcessingResponseProcessor.php index 12c3579b..e7ba71f5 100644 --- a/src/Processor/PaymentResponseProcessor/PaymentProcessingResponseProcessor.php +++ b/src/Processor/PaymentResponseProcessor/PaymentProcessingResponseProcessor.php @@ -21,7 +21,9 @@ final class PaymentProcessingResponseProcessor extends AbstractProcessor use ProcessableResponseTrait; public const PAYMENT_PROCESSING_CODES = ['received', 'processing']; + public const LABEL_PROCESSING = 'bitbag_sylius_adyen_plugin.ui.payment_processing'; + public const REDIRECT_TARGET_ROUTE = 'sylius_shop_homepage'; /** @var UrlGeneratorInterface */ @@ -42,8 +44,11 @@ public function accepts(Request $request, ?PaymentInterface $payment): bool return $this->isResultCodeSupportedForPayment($payment, self::PAYMENT_PROCESSING_CODES); } - public function process(string $code, Request $request, PaymentInterface $payment): string - { + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string { $this->dispatchPaymentStatusReceived($payment); $this->addFlash($request, self::FLASH_INFO, self::LABEL_PROCESSING); diff --git a/src/Processor/PaymentResponseProcessor/ProcessorInterface.php b/src/Processor/PaymentResponseProcessor/ProcessorInterface.php index 29650c78..fd75e1da 100644 --- a/src/Processor/PaymentResponseProcessor/ProcessorInterface.php +++ b/src/Processor/PaymentResponseProcessor/ProcessorInterface.php @@ -17,5 +17,9 @@ interface ProcessorInterface { public function accepts(Request $request, ?PaymentInterface $payment): bool; - public function process(string $code, Request $request, PaymentInterface $payment): string; + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string; } diff --git a/src/Processor/PaymentResponseProcessor/SuccessfulResponseProcessor.php b/src/Processor/PaymentResponseProcessor/SuccessfulResponseProcessor.php index 6f1506e6..1be2fbc9 100644 --- a/src/Processor/PaymentResponseProcessor/SuccessfulResponseProcessor.php +++ b/src/Processor/PaymentResponseProcessor/SuccessfulResponseProcessor.php @@ -50,8 +50,11 @@ public function accepts(Request $request, ?PaymentInterface $payment): bool return $this->isResultCodeSupportedForPayment($payment, self::PAYMENT_PROCEED_CODES); } - public function process(string $code, Request $request, PaymentInterface $payment): string - { + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string { $targetRoute = self::THANKS_ROUTE_NAME; $this->dispatchPaymentStatusReceived($payment); @@ -66,11 +69,11 @@ public function process(string $code, Request $request, PaymentInterface $paymen private function shouldTheAlternativeThanksPageBeShown(Request $request): bool { - if ($request->query->get(self::TOKEN_VALUE_KEY) !== null) { + if (null !== $request->query->get(self::TOKEN_VALUE_KEY)) { return true; } - if ($request->getSession()->get(self::ORDER_ID_KEY) !== null) { + if (null !== $request->getSession()->get(self::ORDER_ID_KEY)) { return false; } diff --git a/src/Processor/PaymentResponseProcessorInterface.php b/src/Processor/PaymentResponseProcessorInterface.php index 3f288d13..ecdcdd13 100644 --- a/src/Processor/PaymentResponseProcessorInterface.php +++ b/src/Processor/PaymentResponseProcessorInterface.php @@ -15,5 +15,9 @@ interface PaymentResponseProcessorInterface { - public function process(string $code, Request $request, PaymentInterface $payment): string; + public function process( + string $code, + Request $request, + PaymentInterface $payment + ): string; } diff --git a/src/Provider/AdyenClientProvider.php b/src/Provider/AdyenClientProvider.php index 5b49c0b4..b634c18e 100644 --- a/src/Provider/AdyenClientProvider.php +++ b/src/Provider/AdyenClientProvider.php @@ -38,6 +38,7 @@ final class AdyenClientProvider implements AdyenClientProviderInterface /** @var ClientPayloadFactoryInterface */ private $clientPayloadFactory; + /** @var PaymentMethodsFilterInterface */ private $paymentMethodsFilter; @@ -95,7 +96,7 @@ public function getClientForCode(string $code): AdyenClientInterface { $paymentMethod = $this->paymentMethodRepository->findOneForAdyenAndCode($code); - if ($paymentMethod === null) { + if (null === $paymentMethod) { throw new UnprocessablePaymentException(); } diff --git a/src/Provider/LoggerProvider.php b/src/Provider/LoggerProvider.php index d9c648dd..4448668b 100644 --- a/src/Provider/LoggerProvider.php +++ b/src/Provider/LoggerProvider.php @@ -1,4 +1,6 @@ -adyenPaymentMethods($order, $code, $token); $result['code'] = $paymentMethod->getCode(); - $result['canBeStored'] = $token !== null; + $result['canBeStored'] = null !== $token; return $result; } @@ -73,7 +74,7 @@ private function getToken(PaymentMethodInterface $paymentMethod, OrderInterface * @var ?CustomerInterface $customer */ $customer = $order->getCustomer(); - if ($customer === null || !$customer->hasUser()) { + if (null === $customer || !$customer->hasUser()) { return null; } @@ -111,7 +112,7 @@ private function filterKeys(array $array): array private function getPaymentMethod(OrderInterface $order, ?string $code = null): PaymentMethodInterface { - if ($code !== null) { + if (null !== $code) { return $this->paymentMethodRepository->getOneForAdyenAndCode($code); } diff --git a/src/Provider/SignatureValidatorProvider.php b/src/Provider/SignatureValidatorProvider.php index 457d5d64..e59ade8d 100644 --- a/src/Provider/SignatureValidatorProvider.php +++ b/src/Provider/SignatureValidatorProvider.php @@ -32,7 +32,7 @@ public function getValidatorForCode(string $code): SignatureValidator { $paymentMethod = $this->paymentMethodRepository->findOneForAdyenAndCode($code); - if ($paymentMethod === null) { + if (null === $paymentMethod) { throw new AdyenNotConfiguredException($code); } $gatewayConfig = $this->getGatewayConfig($paymentMethod); diff --git a/src/Repository/AdyenReferenceRepository.php b/src/Repository/AdyenReferenceRepository.php index e11f8552..386c727f 100644 --- a/src/Repository/AdyenReferenceRepository.php +++ b/src/Repository/AdyenReferenceRepository.php @@ -45,6 +45,7 @@ public function getOneByCodeAndReference(string $code, string $pspReference): Ad /** * @psalm-suppress MixedReturnStatement * @psalm-suppress MixedInferredReturnType + * * @throws NoResultException */ public function getOneForRefundByCodeAndReference(string $code, string $pspReference): AdyenReferenceInterface diff --git a/src/Resolver/Address/StreetAddressResolver.php b/src/Resolver/Address/StreetAddressResolver.php index 29f95db0..c4c176ca 100644 --- a/src/Resolver/Address/StreetAddressResolver.php +++ b/src/Resolver/Address/StreetAddressResolver.php @@ -15,12 +15,14 @@ /** * Ported from: - * @link https://github.com/Adyen/adyen-magento2/blob/master/Helper/Address.php + * + * @see https://github.com/Adyen/adyen-magento2/blob/master/Helper/Address.php */ final class StreetAddressResolver implements StreetAddressResolverInterface { // Regex to extract the house number from the street line if needed (e.g. 'Street address 1 A' => '1 A') private const STREET_FIRST_REGEX = "/(?[[:alnum:].'\- ]+)\s+(?\d{1,10}((\s)?\w{1,3})?(\/\d{1,10})?)$/"; + private const NUMBER_FIRST_REGEX = "/^(?\d{1,10}((\s)?\w{1,3})?(\/\d{1,10})?)\s+(?[[:alnum:].'\- ]+)/u"; public function resolve(string $streetAddress): StreetAddressModelInterface @@ -31,9 +33,10 @@ public function resolve(string $streetAddress): StreetAddressModelInterface // Match addresses where the house number comes first, e.g. 10 D John-Paul's Ave. \preg_match(self::NUMBER_FIRST_REGEX, \trim($streetAddress), $numberFirstAddress); - if (\count($streetFirstAddress) > 0) { + if (0 < \count($streetFirstAddress)) { return $this->getAddress($streetFirstAddress['streetName'] ?? '', $streetFirstAddress['houseNumber'] ?? ''); - } elseif (\count($numberFirstAddress) > 0) { + } + if (0 < \count($numberFirstAddress)) { return $this->getAddress($numberFirstAddress['streetName'] ?? '', $numberFirstAddress['houseNumber'] ?? ''); } diff --git a/src/Resolver/Notification/NotificationResolver.php b/src/Resolver/Notification/NotificationResolver.php index 00a16991..e1cc6370 100644 --- a/src/Resolver/Notification/NotificationResolver.php +++ b/src/Resolver/Notification/NotificationResolver.php @@ -78,7 +78,7 @@ public function resolve(string $paymentCode, Request $request): array $item->paymentCode = $paymentCode; $validationResult = $this->validator->validate($item); - if ($validationResult->count() > 0) { + if (0 < $validationResult->count()) { $this->logger->error( 'Denormalization violations: ' . \var_export($validationResult, true) ); diff --git a/src/Resolver/Notification/NotificationResolver/PaymentNotificationResolver.php b/src/Resolver/Notification/NotificationResolver/PaymentNotificationResolver.php index 38e8ad32..fb08723e 100644 --- a/src/Resolver/Notification/NotificationResolver/PaymentNotificationResolver.php +++ b/src/Resolver/Notification/NotificationResolver/PaymentNotificationResolver.php @@ -22,6 +22,7 @@ final class PaymentNotificationResolver implements CommandResolver { /** @var DispatcherInterface */ private $dispatcher; + /** @var AdyenReferenceRepositoryInterface */ private $adyenReferenceRepository; @@ -33,8 +34,11 @@ public function __construct( $this->adyenReferenceRepository = $adyenReferenceRepository; } - private function fetchPayment(string $paymentCode, string $reference, ?string $originalReference): PaymentInterface - { + private function fetchPayment( + string $paymentCode, + string $reference, + ?string $originalReference + ): PaymentInterface { try { $reference = $this->adyenReferenceRepository->getOneByCodeAndReference( $paymentCode, diff --git a/src/Resolver/Notification/Serializer/NotificationItemNormalizer.php b/src/Resolver/Notification/Serializer/NotificationItemNormalizer.php index 89ae34e9..004c5154 100644 --- a/src/Resolver/Notification/Serializer/NotificationItemNormalizer.php +++ b/src/Resolver/Notification/Serializer/NotificationItemNormalizer.php @@ -24,13 +24,18 @@ final class NotificationItemNormalizer implements DenormalizerAwareInterface, De private const DENORMALIZATION_PROCESSED_FLAG = '_adyen_notification_denormalization_processed'; use DenormalizerAwareTrait; + use NormalizerAwareTrait; /** * @psalm-suppress MixedReturnStatement */ - public function denormalize($data, string $type, string $format = null, array $context = []) - { + public function denormalize( + $data, + string $type, + string $format = null, + array $context = [] + ) { if (!isset($data[self::DENORMALIZATION_PROCESSED_FLAG]) && is_array($data)) { $data['eventCode'] = strtolower((string) $data['eventCode']); $data[self::DENORMALIZATION_PROCESSED_FLAG] = true; @@ -39,10 +44,13 @@ public function denormalize($data, string $type, string $format = null, array $c return $this->denormalizer->denormalize($data, $type, $format, $context); } - public function supportsDenormalization($data, string $type, string $format = null): bool - { + public function supportsDenormalization( + $data, + string $type, + string $format = null + ): bool { return - $type === NotificationItemData::class + NotificationItemData::class === $type && isset($data['eventCode'], $data['paymentMethod']) && !isset($data[self::DENORMALIZATION_PROCESSED_FLAG]) ; @@ -63,8 +71,11 @@ private function getNormalizationMarking($object): string * * @return array */ - public function normalize($object, string $format = null, array $context = []) - { + public function normalize( + $object, + string $format = null, + array $context = [] + ) { if (!isset($context[$this->getNormalizationMarking($object)])) { $context[$this->getNormalizationMarking($object)] = true; } @@ -81,8 +92,11 @@ public function normalize($object, string $format = null, array $context = []) /** * @param mixed $data */ - public function supportsNormalization($data, string $format = null, array $context = []) - { + public function supportsNormalization( + $data, + string $format = null, + array $context = [] + ) { return $data instanceof NotificationItemData && !isset($context[$this->getNormalizationMarking($data)]) diff --git a/src/Resolver/Order/PaymentCheckoutOrderResolver.php b/src/Resolver/Order/PaymentCheckoutOrderResolver.php index b63c801f..22f963e5 100644 --- a/src/Resolver/Order/PaymentCheckoutOrderResolver.php +++ b/src/Resolver/Order/PaymentCheckoutOrderResolver.php @@ -42,7 +42,7 @@ public function __construct( private function getCurrentRequest(): Request { $result = $this->requestStack->getCurrentRequest(); - if ($result === null) { + if (null === $result) { throw new BadRequestException('No request provided'); } diff --git a/src/Resolver/Payment/EventCodeResolver.php b/src/Resolver/Payment/EventCodeResolver.php index 7d8cd670..bda1e551 100644 --- a/src/Resolver/Payment/EventCodeResolver.php +++ b/src/Resolver/Payment/EventCodeResolver.php @@ -16,7 +16,7 @@ final class EventCodeResolver implements EventCodeResolverInterface { public function resolve(NotificationItemData $notificationData): string { - if ($notificationData->eventCode !== self::AUTHORIZATION) { + if (self::AUTHORIZATION !== $notificationData->eventCode) { return (string) $notificationData->eventCode; } diff --git a/src/Resolver/Payment/PaymentDetailsResolver.php b/src/Resolver/Payment/PaymentDetailsResolver.php index 80a04a31..d306c4ab 100644 --- a/src/Resolver/Payment/PaymentDetailsResolver.php +++ b/src/Resolver/Payment/PaymentDetailsResolver.php @@ -54,12 +54,12 @@ private function getPaymentForReference(string $orderNumber): PaymentInterface * @var ?OrderInterface $order */ $order = $this->orderRepository->findOneByNumber($orderNumber); - if ($order === null) { + if (null === $order) { throw new PaymentMethodForReferenceNotFoundException($orderNumber); } $payment = $order->getLastPayment(); - if ($payment === null) { + if (null === $payment) { throw new UnprocessablePaymentException(); } diff --git a/src/Resolver/Product/ThumbnailUrlResolver.php b/src/Resolver/Product/ThumbnailUrlResolver.php index 5e69931f..f3888ab0 100644 --- a/src/Resolver/Product/ThumbnailUrlResolver.php +++ b/src/Resolver/Product/ThumbnailUrlResolver.php @@ -19,7 +19,9 @@ final class ThumbnailUrlResolver implements ThumbnailUrlResolverInterface { private const FILTER_NAME = 'sylius_shop_product_thumbnail'; + private const IMAGE_TYPE = 'main'; + /** @var CacheManager */ private $cacheManager; @@ -34,7 +36,7 @@ private function getProductImagesForVariant(ProductVariantInterface $productVari * @var ProductInterface|null $product */ $product = $productVariant->getProduct(); - if ($product === null) { + if (null === $product) { return []; } @@ -58,7 +60,7 @@ private function getProductImage(ProductVariantInterface $productVariant): ?Prod public function resolve(ProductVariantInterface $productVariant): ?string { $image = $this->getProductImage($productVariant); - if ($image === null) { + if (null === $image) { return null; } diff --git a/src/Traits/GatewayConfigFromPaymentTrait.php b/src/Traits/GatewayConfigFromPaymentTrait.php index 48e137ab..d724c844 100644 --- a/src/Traits/GatewayConfigFromPaymentTrait.php +++ b/src/Traits/GatewayConfigFromPaymentTrait.php @@ -19,7 +19,7 @@ trait GatewayConfigFromPaymentTrait private function getGatewayConfig(PaymentMethodInterface $paymentMethod): GatewayConfigInterface { $gatewayConfig = $paymentMethod->getGatewayConfig(); - if ($gatewayConfig === null) { + if (null === $gatewayConfig) { throw new AdyenNotConfiguredException((string) $paymentMethod->getCode()); } diff --git a/src/Traits/OrderFromPaymentTrait.php b/src/Traits/OrderFromPaymentTrait.php index 5c63367d..6a69404e 100644 --- a/src/Traits/OrderFromPaymentTrait.php +++ b/src/Traits/OrderFromPaymentTrait.php @@ -18,7 +18,7 @@ trait OrderFromPaymentTrait private function getOrderFromPayment(PaymentInterface $payment): OrderInterface { $result = $payment->getOrder(); - if ($result === null) { + if (null === $result) { throw new \InvalidArgumentException(sprintf('Payment #%d has no order', (int) $payment->getId())); } diff --git a/src/Traits/PayableOrderPaymentTrait.php b/src/Traits/PayableOrderPaymentTrait.php index 4527559a..bae82ef6 100644 --- a/src/Traits/PayableOrderPaymentTrait.php +++ b/src/Traits/PayableOrderPaymentTrait.php @@ -19,11 +19,11 @@ public function getPayablePayment(OrderInterface $order): PaymentInterface { $payment = $order->getLastPayment(PaymentInterface::STATE_NEW); - if ($payment === null) { + if (null === $payment) { $payment = $order->getLastPayment(PaymentInterface::STATE_CART); } - if ($payment === null) { + if (null === $payment) { throw new \InvalidArgumentException( sprintf('Order #%d has no Payment associated', (int) $order->getId()) ); diff --git a/src/Traits/PaymentFromOrderTrait.php b/src/Traits/PaymentFromOrderTrait.php index bb497da9..39cc5875 100644 --- a/src/Traits/PaymentFromOrderTrait.php +++ b/src/Traits/PaymentFromOrderTrait.php @@ -29,7 +29,7 @@ private function getPayment(OrderInterface $order, ?string $state = null): Payme { $payment = $order->getLastPayment($state); - if ($payment === null) { + if (null === $payment) { throw new \InvalidArgumentException( sprintf('No payment associated with Order #%d', (int) $order->getId()) ); diff --git a/src/Validator/Constraint/AdyenCredentialsValidator.php b/src/Validator/Constraint/AdyenCredentialsValidator.php index 981e7f2f..f24218e6 100644 --- a/src/Validator/Constraint/AdyenCredentialsValidator.php +++ b/src/Validator/Constraint/AdyenCredentialsValidator.php @@ -33,11 +33,11 @@ public function __construct(AdyenTransportFactory $adyenTransportFactory) private function dispatchException(AdyenException $exception): void { - if ($exception->getCode() === Response::HTTP_UNAUTHORIZED) { + if (Response::HTTP_UNAUTHORIZED === $exception->getCode()) { throw new InvalidApiKeyException(); } - if ($exception->getCode() === Response::HTTP_FORBIDDEN) { + if (Response::HTTP_FORBIDDEN === $exception->getCode()) { throw new InvalidMerchantAccountException(); } @@ -46,11 +46,11 @@ private function dispatchException(AdyenException $exception): void private function validateArguments(?string $merchantAccount, ?string $apiKey): void { - if ($merchantAccount === null || $merchantAccount === '') { + if (null === $merchantAccount || '' === $merchantAccount) { throw new InvalidMerchantAccountException(); } - if ($apiKey === null || $apiKey === '') { + if (null === $apiKey || '' === $apiKey) { throw new InvalidApiKeyException(); } } @@ -58,8 +58,11 @@ private function validateArguments(?string $merchantAccount, ?string $apiKey): v /** * @throws AuthenticationException|AdyenException */ - public function isApiKeyValid(string $environment, ?string $merchantAccount, ?string $apiKey): bool - { + public function isApiKeyValid( + string $environment, + ?string $merchantAccount, + ?string $apiKey + ): bool { $this->validateArguments($merchantAccount, $apiKey); $payload = [ diff --git a/src/Validator/Constraint/ProvinceAddressConstraintValidatorDecorator.php b/src/Validator/Constraint/ProvinceAddressConstraintValidatorDecorator.php index 21c8bc02..c0ed5191 100644 --- a/src/Validator/Constraint/ProvinceAddressConstraintValidatorDecorator.php +++ b/src/Validator/Constraint/ProvinceAddressConstraintValidatorDecorator.php @@ -15,7 +15,6 @@ use Sylius\Component\Core\Model\AddressInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\ConstraintViolationInterface; use Webmozart\Assert\Assert; class ProvinceAddressConstraintValidatorDecorator extends ConstraintValidator @@ -26,6 +25,7 @@ class ProvinceAddressConstraintValidatorDecorator extends ConstraintValidator /** @var ProvinceAddressConstraintValidator */ private $decorated; + /** @var array|string[] */ private $provinceRequiredCountriesList; @@ -57,7 +57,7 @@ public function validate($value, Constraint $constraint): void return; } - if (!is_null($value->getProvinceCode()) || !is_null($value->getProvinceName())) { + if (null !== $value->getProvinceCode() || null !== $value->getProvinceName()) { return; }