SettingsManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 86
rs 10
ccs 20
cts 20
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultDriver() 0 4 1
A createMemoryDriver() 0 4 1
A createArrayDriver() 0 4 1
A createJsonDriver() 0 7 1
A createDatabaseDriver() 0 7 1
A getConfig() 0 7 1
1
<?php namespace Arcanedev\Settings;
2
3
use Illuminate\Support\Manager;
4
5
/**
6
 * Class     SettingsManager
7
 *
8
 * @package  Arcanedev\Settings
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @method   mixed  get(mixed $key, mixed $default = null)
12
 * @method   bool   has(string $key)
13
 * @method   void   set(string $key, mixed $value = null)
14
 * @method   void   forget(string $key)
15
 * @method   void   reset()
16
 * @method   array  all()
17
 * @method   array  save()
18
 */
19
class SettingsManager extends Manager
20
{
21
    /* ------------------------------------------------------------------------------------------------
22
     |  Main Functions
23
     | ------------------------------------------------------------------------------------------------
24
     */
25
    /**
26
     * Get the default driver name.
27
     *
28
     * @return string
29
     */
30 12
    public function getDefaultDriver()
31
    {
32 12
        return $this->getConfig('default', 'json');
33
    }
34
35
    /* ------------------------------------------------------------------------------------------------
36
     |  Driver Functions
37
     | ------------------------------------------------------------------------------------------------
38
     */
39
    /**
40
     * Create the Json driver store.
41
     *
42
     * @return string
43
     */
44 9
    public function createJsonDriver()
45
    {
46 9
        return new Stores\JsonStore(
47 9
            $this->app['files'],
48 9
            $this->getConfig('stores.json.path')
49 9
        );
50 3
    }
51
52
    /**
53
     * Create the Database driver store.
54
     *
55
     * @return string
56
     */
57 3
    public function createDatabaseDriver()
58
    {
59 3
        return new Stores\DatabaseStore(
60 3
            $this->getConfig('stores.database.connection'),
61 3
            $this->getConfig('stores.database.table')
62 3
        );
63
    }
64
65
    /**
66
     * Create the Memory driver store.
67
     *
68
     * @return string
69
     */
70 3
    public function createMemoryDriver()
71
    {
72 3
        return new Stores\MemoryStore;
73
    }
74
75
    /**
76
     * Create the Array driver store.
77
     *
78
     * @return string
79
     */
80 3
    public function createArrayDriver()
81
    {
82 3
        return new Stores\ArrayStore;
83
    }
84
85
    /* ------------------------------------------------------------------------------------------------
86
     |  Other Functions
87
     | ------------------------------------------------------------------------------------------------
88
     */
89
    /**
90
     * Get config.
91
     *
92
     * @param  string      $key
93
     * @param  mixed|null  $default
94
     *
95
     * @return string
96
     */
97 12
    protected function getConfig($key, $default = null)
98
    {
99
        /** @var  \Illuminate\Config\Repository  $config */
100 12
        $config = $this->app['config'];
101
102 12
        return $config->get("settings.$key", $default);
103
    }
104
}
105