Passed
Push — develop ( 0d66a7...37c69c )
by Laurent
05:34 queued 02:39
created

DeleteSettingsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Infrastructure\Settings\Controller;
15
16
use Administration\Domain\Settings\Command\DeleteSettings;
17
use Core\Infrastructure\Common\MessengerCommandBus;
18
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
19
use Symfony\Component\HttpFoundation\RedirectResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
23
class DeleteSettingsController extends AbstractController
24
{
25
    private MessengerCommandBus $commandBus;
26
27
    public function __construct(MessengerCommandBus $commandBus)
28
    {
29
        $this->commandBus = $commandBus;
30
    }
31
32
    public function __invoke(Request $request, string $uuid): Response
33
    {
34
        try {
35
            $command = new DeleteSettings($uuid);
36
            $this->commandBus->dispatch($command);
37
        } catch (\RuntimeException $exception) {
38
            $this->addFlash('errors', $exception->getMessage());
39
40
            return $this->render('Administration/Settings/index.html.twig', [
41
                'errors' => $exception,
42
            ]);
43
        }
44
        $this->addFlash('success', 'Settings deleted started!');
45
46
        return new RedirectResponse($this->generateUrl('admin_settings_index'));
47
    }
48
}
49