Passed
Push — master ( 366f40...c67819 )
by Christian
13:04 queued 10s
created

Storefront/Controller/AccountPaymentController.php (1 issue)

1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Controller;
4
5
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
6
use Shopware\Core\Checkout\Customer\CustomerEntity;
7
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractChangePaymentMethodRoute;
8
use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException;
9
use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
10
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
11
use Shopware\Core\Framework\Routing\Annotation\Since;
12
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
13
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
14
use Shopware\Core\System\SalesChannel\SalesChannelContext;
15
use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoader;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Routing\Annotation\Route;
20
21
/**
22
 * @RouteScope(scopes={"storefront"})
23
 */
24
class AccountPaymentController extends StorefrontController
25
{
26
    /**
27
     * @var AccountPaymentMethodPageLoader
28
     */
29
    private $paymentMethodPageLoader;
30
31
    /**
32
     * @var AbstractChangePaymentMethodRoute
33
     */
34
    private $changePaymentMethodRoute;
35
36
    public function __construct(
37
        AccountPaymentMethodPageLoader $paymentMethodPageLoader,
38
        AbstractChangePaymentMethodRoute $changePaymentMethodRoute
39
    ) {
40
        $this->paymentMethodPageLoader = $paymentMethodPageLoader;
41
        $this->changePaymentMethodRoute = $changePaymentMethodRoute;
42
    }
43
44
    /**
45
     * @Since("6.0.0.0")
46
     * @LoginRequired()
47
     * @Route("/account/payment", name="frontend.account.payment.page", options={"seo"="false"}, methods={"GET"})
48
     *
49
     * @throws CustomerNotLoggedInException
50
     */
51
    public function paymentOverview(Request $request, SalesChannelContext $context): Response
52
    {
53
        $page = $this->paymentMethodPageLoader->load($request, $context);
54
55
        return $this->renderStorefront('@Storefront/storefront/page/account/payment/index.html.twig', ['page' => $page]);
56
    }
57
58
    /**
59
     * @Since("6.0.0.0")
60
     * @LoginRequired()
61
     * @Route("/account/payment", name="frontend.account.payment.save", methods={"POST"})
62
     *
63
     * @throws CustomerNotLoggedInException
64
     */
65
    public function savePayment(RequestDataBag $requestDataBag, SalesChannelContext $context, ?CustomerEntity $customer = null): Response
66
    {
67
        try {
68
            $paymentMethodId = $requestDataBag->getAlnum('paymentMethodId');
69
70
            /* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */
71
            $this->changePaymentMethodRoute->change(
72
                $paymentMethodId,
73
                $requestDataBag,
74
                $context,
75
                $customer
0 ignored issues
show
The call to Shopware\Core\Checkout\C...ntMethodRoute::change() has too many arguments starting with $customer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
            $this->changePaymentMethodRoute->/** @scrutinizer ignore-call */ 
76
                                             change(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
76
            );
77
        } catch (UnknownPaymentMethodException | InvalidUuidException $exception) {
78
            $this->addFlash('danger', $this->trans('error.' . $exception->getErrorCode()));
79
80
            return $this->forwardToRoute('frontend.account.payment.page', ['success' => false]);
81
        }
82
83
        $this->addFlash('success', $this->trans('account.paymentSuccess'));
84
85
        return new RedirectResponse($this->generateUrl('frontend.account.payment.page'));
86
    }
87
}
88