Completed
Pull Request — master (#15)
by Cesar
01:41
created

SettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A settingsList() 0 4 1
A settingsSave() 0 7 1
A settingsClear() 0 5 1
1
<?php
2
3
namespace App\Controller;
4
5
use App\Service\SettingsService;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class SettingsController
13
 * @package App\Controller
14
 *
15
 * @Route("/settings", name="settings-")
16
 */
17
class SettingsController extends AbstractController
18
{
19
    /**
20
     * @var SettingsService
21
     */
22
    protected $settingsService;
23
24
    /**
25
     * DefaultController constructor.
26
     * @param SettingsService $settingsService
27
     */
28
    public function __construct(SettingsService $settingsService)
29
    {
30
        $this->settingsService = $settingsService;
31
    }
32
33
    /**
34
     * @Route("/", name="index", methods={"GET"})
35
     *
36
     * @return Response
37
     */
38
    public function settingsList()
39
    {
40
        return $this->render('settings/index.html.twig');
41
    }
42
43
    /**
44
     * @Route("/", name="save", methods={"POST"})
45
     *
46
         * @return Response
47
     */
48
    public function settingsSave()
49
    {
50
        $request = Request::createFromGlobals();
51
        $settings = $request->request->all();
52
        $this->settingsService->storeSettings($settings);
53
        return new Response();
54
    }
55
56
    /**
57
     * @Route("/", name="clear", methods={"DELETE"})
58
     *
59
     * @return Response
60
     */
61
    public function settingsClear()
62
    {
63
        $this->settingsService->clearSettings();
64
        return new Response();
65
    }
66
}
67