Passed
Push — master ( 6957cf...3bb145 )
by Joachim
04:59
created

SendReportAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStockMovementPlugin\Controller\Action;
6
7
use Setono\SyliusStockMovementPlugin\Message\Command\SendReport;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
10
use Symfony\Component\Messenger\MessageBusInterface;
11
use Symfony\Component\Routing\RouterInterface;
12
13
final class SendReportAction
14
{
15
    /** @var MessageBusInterface */
16
    private $commandBus;
17
18
    /** @var RouterInterface */
19
    private $router;
20
21
    /** @var FlashBagInterface */
22
    private $flashBag;
23
24
    public function __construct(
25
        MessageBusInterface $commandBus,
26
        RouterInterface $router,
27
        FlashBagInterface $flashBag
28
    ) {
29
        $this->commandBus = $commandBus;
30
        $this->router = $router;
31
        $this->flashBag = $flashBag;
32
    }
33
34
    public function __invoke($id)
35
    {
36
        $this->commandBus->dispatch(new SendReport($id));
37
38
        $this->flashBag->add('success', 'setono_sylius_stock_movement.report_sent');
39
40
        return new RedirectResponse($this->router->generate('setono_sylius_stock_movement_admin_report_show', ['id' => $id]));
41
    }
42
}
43