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

DeleteSettingsController::__invoke()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 3
nop 2
dl 0
loc 15
rs 9.9666
c 1
b 0
f 0
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