Completed
Push — master ( 5e1cd2...38f1ea )
by Matze
03:32
created

Settings::__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 0
Metric Value
c 0
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\Settings;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Annotations\Annotations\Service;
7
8
/**
9
 * @api
10
 * @Service("User.Settings", public=false)
11
 */
12
class Settings
13
{
14
15
    /**
16
     * @var Gateway
17
     */
18
    private $gateway;
19
20
    /**
21
     * @Inject("@User.Settings.Gateway")
22
     * @param Gateway $gateway
23
     */
24 4
    public function __construct(Gateway $gateway)
25
    {
26 4
        $this->gateway = $gateway;
27 4
    }
28
29
    /**
30
     * @param int $userId
31
     * @param string $setting
32
     * @return string
33
     */
34 2
    public function get(int $userId, string $setting)
35
    {
36 2
        $value = $this->gateway->get($userId, $setting);
37
38 2
        if (empty($value) && $userId) {
39 1
            $value = $this->get(0, $setting);
40
        }
41
42 2
        return $value;
43
    }
44
45
    /**
46
     * @param int $userId
47
     * @return string[]
48
     */
49 1
    public function getAll(int $userId) : array
50
    {
51 1
        $values = $this->gateway->getAll($userId);
52
53 1
        if ($userId) {
54 1
            $values = array_merge($this->getAll(0), $values);
55
        }
56
57 1
        return $values;
58
    }
59
60
    /**
61
     * @param int $userId
62
     * @param string $setting
63
     * @param string $value
64
     */
65 1
    public function set(int $userId, string $setting, $value)
66
    {
67 1
        $this->gateway->set($userId, $setting, $value);
68 1
    }
69
}
70