Completed
Push — master ( a818cb...b1c6ca )
by Kamil
07:13 queued 10s
created

ResendOrderConfirmationEmailAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\AdminBundle\Action;
15
16
use Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManagerInterface;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
19
use Symfony\Component\HttpFoundation\RedirectResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\HttpFoundation\Session\Session;
23
use Symfony\Component\HttpFoundation\Session\SessionInterface;
24
use Symfony\Component\HttpKernel\Exception\HttpException;
25
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26
use Symfony\Component\Security\Csrf\CsrfToken;
27
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
28
29
final class ResendOrderConfirmationEmailAction
30
{
31
    /** @var OrderRepositoryInterface */
32
    private $orderRepository;
33
34
    /** @var OrderEmailManagerInterface */
35
    private $orderEmailManager;
36
37
    /** @var CsrfTokenManagerInterface */
38
    private $csrfTokenManager;
39
40
    /** @var Session */
41
    private $session;
42
43
    public function __construct(
44
        OrderRepositoryInterface $orderRepository,
45
        OrderEmailManagerInterface $orderEmailManager,
46
        CsrfTokenManagerInterface $csrfTokenManager,
47
        SessionInterface $session
48
    ) {
49
        $this->orderRepository = $orderRepository;
50
        $this->orderEmailManager = $orderEmailManager;
51
        $this->csrfTokenManager = $csrfTokenManager;
52
        $this->session = $session;
0 ignored issues
show
Documentation Bug introduced by
It seems like $session of type object<Symfony\Component...ssion\SessionInterface> is incompatible with the declared type object<Symfony\Component...dation\Session\Session> of property $session.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
    }
54
55
    public function __invoke(Request $request): Response
56
    {
57
        $orderId = $request->attributes->get('id');
58
59
        if (!$this->csrfTokenManager->isTokenValid(new CsrfToken($orderId, $request->query->get('_csrf_token')))) {
60
            throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
61
        }
62
63
        /** @var OrderInterface|null $order */
64
        $order = $this->orderRepository->find($orderId);
65
        if ($order === null) {
66
            throw new NotFoundHttpException(sprintf('The order with id %s has not been found', $orderId));
67
        }
68
69
        $this->orderEmailManager->sendConfirmationEmail($order);
70
71
        $this->session->getFlashBag()->add(
72
            'success',
73
            'sylius.email.order_confirmation_resent'
74
        );
75
76
        return new RedirectResponse($request->headers->get('referer'));
77
    }
78
}
79