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

SettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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