Completed
Push — master ( 150272...5e1cd2 )
by Matze
14:28 queued 09:42
created

SettingsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 6 1
A set() 0 9 1
1
<?php
2
3
namespace BrainExe\Core\Authentication\Controller;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\Annotations\Controller;
7
use BrainExe\Core\Annotations\Guest;
8
use BrainExe\Core\Annotations\Route;
9
use BrainExe\Core\Authentication\Settings\Settings;
10
use Symfony\Component\HttpFoundation\Request;
11
12
/**
13
 * @Controller("Authentication.Controller.Settings")
14
 */
15
class SettingsController
16
{
17
    /**
18
     * @var Settings
19
     */
20
    private $settings;
21
22
    /**
23
     * @Inject("@User.Settings")
24
     * @param Settings $settings
25
     */
26 2
    public function __construct(Settings $settings)
27
    {
28 2
        $this->settings = $settings;
29 2
    }
30
31
    /**
32
     * @param Request $request
33
     * @return string[]
34
     * @Route("/settings/", name="settings.all", methods="GET")
35
     * @Guest
36
     */
37 1
    public function all(Request $request)
38
    {
39 1
        $userId = $request->attributes->getInt('user_id');
40
41 1
        return $this->settings->getAll($userId);
42
    }
43
44
    /**
45
     * @param Request $request
46
     * @param string $key
47
     * @return bool
48
     * @Route("/settings/{key}/", name="settings.set", methods="POST")
49
     */
50 1
    public function set(Request $request, string $key) : bool
51
    {
52 1
        $userId = $request->attributes->getInt('user_id');
53 1
        $value  = $request->request->get('value');
54
55 1
        $this->settings->set($userId, $key, $value);
56
57 1
        return true;
58
    }
59
}
60