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

Settings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 10 2
A __construct() 0 4 1
A set() 0 4 1
A get() 0 10 3
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