Settings   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

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