Skip to content

Commit

Permalink
Merge pull request #66 from BitBagCommerce/OPSRC-496/Add_bitbag_codin…
Browse files Browse the repository at this point in the history
…g_standard_to_every_plugin

OPSRC-496/Add bitbag coding standard and ecs fix
  • Loading branch information
fabulousPuppet authored Jul 29, 2022
2 parents 2359cb9 + b911adf commit 8e36bb4
Show file tree
Hide file tree
Showing 70 changed files with 327 additions and 170 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@
/behat.yml
/phpspec.yml
/phpunit.xml

ecs.php
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php');

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
__DIR__ . '/tests',
]);
};
3 changes: 1 addition & 2 deletions src/BitBagSyliusAdyenPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Bus/Command/CreateReferenceForRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
10 changes: 5 additions & 5 deletions src/Bus/Handler/AlterPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -63,7 +63,7 @@ private function getPayment(OrderInterface $order): ?PaymentInterface
}

$payment = $order->getLastPayment(PaymentInterface::STATE_AUTHORIZED);
if ($payment === null) {
if (null === $payment) {
return null;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bus/Handler/CreateReferenceForPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Bus/Handler/GetTokenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function getUser(): ?UserInterface
{
$token = $this->tokenStorage->getToken();

if ($token === null) {
if (null === $token) {
return null;
}

Expand All @@ -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());
}

Expand All @@ -82,7 +82,7 @@ public function __invoke(GetToken $getTokenQuery): ?AdyenTokenInterface
$customer
);

if ($token !== null) {
if (null !== $token) {
return $token;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bus/Handler/PaymentFinalizationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
}
6 changes: 3 additions & 3 deletions src/Bus/Handler/RefundPaymentGeneratedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function createReference(
PaymentInterface $payment
): void {
$refund = $this->refundPaymentRepository->find($refundPaymentGenerated->id());
if ($refund === null) {
if (null === $refund) {
return;
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Bus/Handler/TakeOverPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
final class TakeOverPaymentHandler implements MessageHandlerInterface
{
use PayableOrderPaymentTrait;

use PaymentFromOrderTrait;

/** @var PaymentMethodRepositoryInterface */
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/PaymentCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function createForEvent(
PaymentInterface $payment,
?NotificationItemData $notificationItemData = null
): PaymentLifecycleCommand {
if ($notificationItemData !== null) {
if (null !== $notificationItemData) {
$event = $this->eventCodeResolver->resolve($notificationItemData);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Bus/PaymentCommandFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/Callback/PreserveOrderTokenUponRedirectionCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(OrderInterface $order): void
{
$tokenValue = $order->getTokenValue();

if ($tokenValue === null) {
if (null === $tokenValue) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Client/AdyenTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
14 changes: 7 additions & 7 deletions src/Client/ClientPayloadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -119,7 +119,7 @@ public function createForSubmitPayment(
?AdyenTokenInterface $adyenToken = null
): array {
$billingAddress = $order->getBillingAddress();
$countryCode = $billingAddress !== null
$countryCode = null !== $billingAddress
? (string) $billingAddress->getCountryCode()
: null
;
Expand Down Expand Up @@ -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;
}
Expand All @@ -281,7 +281,7 @@ private function injectShopperReference(
array $payload,
?AdyenTokenInterface $customerIdentifier
): array {
if ($customerIdentifier !== null) {
if (null !== $customerIdentifier) {
$payload['shopperReference'] = $customerIdentifier->getIdentifier();
}

Expand All @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions src/Client/ClientPayloadFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Client/PaymentMethodsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
Expand Down
Loading

0 comments on commit 8e36bb4

Please sign in to comment.