Settings::getAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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