Manager   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 4 1
A add() 0 12 2
A get() 0 8 2
A getPath() 0 4 1
A getClassName() 0 4 1
1
<?php
2
3
namespace League\CLImate\Settings;
4
5
class Manager
6
{
7
    /**
8
     * An array of settings that have been... set
9
     *
10
     * @var array $settings
11
     */
12
    protected $settings = [];
13
14
    /**
15
     * Check and see if the requested setting is a valid, registered setting
16
     *
17
     * @param  string  $name
18
     *
19
     * @return boolean
20
     */
21 48
    public function exists($name)
22
    {
23 48
        return class_exists($this->getPath($name));
24
    }
25
26
    /**
27
     * Add a setting
28
     *
29
     * @param string $name
30
     * @param mixed  $value
31
     */
32 44
    public function add($name, $value)
33
    {
34 44
        $setting = $this->getPath($name);
35 44
        $key     = $this->getClassName($name);
36
37
        // If the current key doesn't exist in the settings array, set it up
38 44
        if (!array_key_exists($name, $this->settings)) {
39 44
            $this->settings[$key] = new $setting();
40 44
        }
41
42 44
        $this->settings[$key]->add($value);
43 44
    }
44
45
    /**
46
     * Get the value of the requested setting if it exists
47
     *
48
     * @param  string $key
49
     *
50
     * @return mixed
51
     */
52 80
    public function get($key)
53
    {
54 80
        if (array_key_exists($key, $this->settings)) {
55 44
            return $this->settings[$key];
56
        }
57
58 36
        return false;
59
    }
60
61
    /**
62
     * Get the short name for the requested settings class
63
     *
64
     * @param  string $name
65
     *
66
     * @return string
67
     */
68 48
    protected function getPath($name)
69
    {
70 48
        return 'League\CLImate\Settings\\' . $this->getClassName($name);
71
    }
72
73
    /**
74
     * Get the short class name for the setting
75
     *
76
     * @param  string $name
77
     *
78
     * @return string
79
     */
80 48
    protected function getClassName($name)
81
    {
82 48
        return ucwords(str_replace('add_', '', $name));
83
    }
84
}
85