Skip to content

Commit

Permalink
Resolve a code sniffer issues
Browse files Browse the repository at this point in the history
AD4CR22I-9
  • Loading branch information
Tamara committed Jan 8, 2025
1 parent 19f2b25 commit 01eafec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
40 changes: 28 additions & 12 deletions src/Service/ExpressCheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function __construct(
PaymentMethodsFilterService $paymentMethodsFilterService,
Currency $currencyUtil,
KernelInterface $kernel
)
{
) {
$this->cartService = $cartService;
$this->expressCheckoutRepository = $expressCheckoutRepository;
$this->paymentMethodsFilterService = $paymentMethodsFilterService;
Expand Down Expand Up @@ -94,7 +93,14 @@ public function getExpressCheckoutConfigOnProductPage(
string $formattedHandlerIdentifier = ''
): array {
// Creating new cart
$cartData = $this->createCart($productId, $quantity, $salesChannelContext, $newAddress, $newShipping, $formattedHandlerIdentifier);
$cartData = $this->createCart(
$productId,
$quantity,
$salesChannelContext,
$newAddress,
$newShipping,
$formattedHandlerIdentifier
);

$cart = $cartData['cart'];

Expand Down Expand Up @@ -176,7 +182,8 @@ public function createCart(
$paymentMethod = $salesChannelContext->getPaymentMethod();
if ($formattedHandlerIdentifier !== '') {
// Express checkout payment method
$paymentMethod = $this->paymentMethodsFilterService->getPaymentMethodByFormattedHandler($formattedHandlerIdentifier, $salesChannelContext->getContext());
$paymentMethod = $this->paymentMethodsFilterService
->getPaymentMethodByFormattedHandler($formattedHandlerIdentifier, $salesChannelContext->getContext());
}

// Resolving shipping location
Expand All @@ -200,8 +207,20 @@ public function createCart(

// Recreate context with selected shipping method
$updatedSalesChannelContext = $this->isVersion64
? $this->createContextFor64($salesChannelContext, $token, $shippingLocation, $paymentMethod, $shippingMethod)
: $this->createContextFor65($salesChannelContext, $token, $shippingLocation, $paymentMethod, $shippingMethod);
? $this->createContextFor64(
$salesChannelContext,
$token,
$shippingLocation,
$paymentMethod,
$shippingMethod
)
: $this->createContextFor65(
$salesChannelContext,
$token,
$shippingLocation,
$paymentMethod,
$shippingMethod
);

// Recalculate the cart
$cart = $this->cartService->recalculate($cart, $updatedSalesChannelContext);
Expand Down Expand Up @@ -232,8 +251,7 @@ private function resolveShippingMethod(
SalesChannelContext $salesChannelContext,
Cart $cart,
array $newShipping
): ShippingMethodEntity
{
): ShippingMethodEntity {
// Fetch available shipping methods
$filteredMethods = $this->expressCheckoutRepository->fetchAvailableShippingMethods($salesChannelContext, $cart);

Expand Down Expand Up @@ -269,8 +287,7 @@ private function createContextFor64(
ShippingLocation $shippingLocation,
PaymentMethodEntity $paymentMethod,
?ShippingMethodEntity $shippingMethod = null
): SalesChannelContext
{
): SalesChannelContext {
return new SalesChannelContext(
$salesChannelContext->getContext(),
$token,
Expand Down Expand Up @@ -306,8 +323,7 @@ private function createContextFor65(
ShippingLocation $shippingLocation,
PaymentMethodEntity $paymentMethod,
?ShippingMethodEntity $shippingMethod = null
): SalesChannelContext
{
): SalesChannelContext {
return new SalesChannelContext(
$salesChannelContext->getContext(),
$token,
Expand Down
28 changes: 16 additions & 12 deletions src/Service/PaymentMethodsFilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ public function __construct(
ExpressCheckoutRepository $expressCheckoutRepository,
Currency $currency,
AbstractPaymentMethodRoute $paymentMethodRoute,
$paymentMethodRepository
)
{
$paymentMethodRepository
) {
$this->configurationService = $configurationService;
$this->paymentMethodsService = $paymentMethodsService;
$this->paymentMethodRoute = $paymentMethodRoute;
Expand Down Expand Up @@ -342,8 +341,7 @@ public function getGiftCardPaymentMethodId(SalesChannelContext $context): ?strin
public function getAvailableExpressCheckoutPaymentMethods(
Cart $cart,
SalesChannelContext $salesChannelContext
): PaymentMethodsResponse
{
): PaymentMethodsResponse {
$googlePayAvailable = $this->configurationService->isGooglePayExpressCheckoutEnabled();
$payPalAvailable = $this->configurationService->isPayPalExpressCheckoutEnabled();
$applePayAvailable = $this->configurationService->isApplePayExpressCheckoutEnabled();
Expand All @@ -367,7 +365,8 @@ public function getAvailableExpressCheckoutPaymentMethods(
->getElements();

foreach ($salesChannelPaymentMethodEntities as $paymentMethodEntity) {
if ( $paymentMethodEntity->getFormattedHandlerIdentifier() === 'handler_adyen_googlepaypaymentmethodhandler') {
if ($paymentMethodEntity->getFormattedHandlerIdentifier()
=== 'handler_adyen_googlepaypaymentmethodhandler') {
$googlePayInSalesChannel = true;
continue;
}
Expand All @@ -377,7 +376,8 @@ public function getAvailableExpressCheckoutPaymentMethods(
continue;
}

if ($paymentMethodEntity->getFormattedHandlerIdentifier() === 'handler_adyen_applepaypaymentmethodhandler') {
if ($paymentMethodEntity->getFormattedHandlerIdentifier()
=== 'handler_adyen_applepaypaymentmethodhandler') {
$applePayInSalesChannel = true;
}
}
Expand Down Expand Up @@ -433,8 +433,10 @@ public function getAvailableExpressCheckoutPaymentMethods(
* @param Context $context
* @return PaymentMethodEntity|null
*/
public function getPaymentMethodByFormattedHandler(string $formattedHandlerIdentifier, Context $context): ?PaymentMethodEntity
{
public function getPaymentMethodByFormattedHandler(
string $formattedHandlerIdentifier,
Context $context
): ?PaymentMethodEntity {
$criteria = new Criteria();

// Fetch all payment methods
Expand All @@ -461,8 +463,7 @@ public function getPaymentMethodByFormattedHandler(string $formattedHandlerIdent
private function getSalesChannelPaymentMethodEntitiesFilteredByRules(
Cart $cart,
SalesChannelContext $salesChannelContext
): PaymentMethodCollection
{
): PaymentMethodCollection {
$salesChannelPaymentMethodIs = $salesChannelContext->getSalesChannel()
->getPaymentMethodIds();
$criteria = new Criteria();
Expand All @@ -473,7 +474,10 @@ private function getSalesChannelPaymentMethodEntitiesFilteredByRules(
$paymentMethods = $this->paymentMethodRepository->search($criteria, $salesChannelContext->getContext())
->getEntities();

return $paymentMethods->filter(function (PaymentMethodEntity $paymentMethodEntity) use ($cart, $salesChannelContext) {
return $paymentMethods->filter(function (PaymentMethodEntity $paymentMethodEntity) use (
$cart,
$salesChannelContext
) {
$availabilityRule = $paymentMethodEntity->getAvailabilityRule();
if (!$availabilityRule) {
return true; // No rule means it's always available
Expand Down
8 changes: 3 additions & 5 deletions src/Service/PaymentMethodsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public function getPaymentMethods(
SalesChannelContext $context,
string $orderId = '',
int $amount = 0
): PaymentMethodsResponse
{
): PaymentMethodsResponse {
$requestData = $this->buildPaymentMethodsRequestData($context, $orderId, $amount);

$paymentRequestString = json_encode($requestData);
Expand Down Expand Up @@ -212,8 +211,7 @@ private function buildPaymentMethodsRequestData(
SalesChannelContext $context,
string $orderId = '',
int $amount = 0
): array
{
): array {
$merchantAccount = $this->configurationService->getMerchantAccount($context->getSalesChannel()->getId());

if (!$merchantAccount) {
Expand All @@ -225,7 +223,7 @@ private function buildPaymentMethodsRequestData(
// Retrieve data from cart if no order is created yet
if ($orderId === '') {
$currency = $context->getCurrency()->getIsoCode();
if ($amount === 0){
if ($amount === 0) {
$cart = $this->cartService->getCart($context->getToken(), $context);
$amount = $this->currency->sanitize($cart->getPrice()->getTotalPrice(), $currency);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Service/Repository/ExpressCheckoutRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class ExpressCheckoutRepository
public function __construct(
EntityRepository $shippingMethodRepository,
EntityRepository $countryRepository
)
{
) {
$this->shippingMethodRepository = $shippingMethodRepository;
$this->countryRepository = $countryRepository;
}
Expand Down Expand Up @@ -120,5 +119,4 @@ public function resolveCountry(SalesChannelContext $salesChannelContext, array $

return $country;
}

}
}

0 comments on commit 01eafec

Please sign in to comment.