Completed
Push — master ( 2da7a8...7e6b77 )
by Faiz
01:55
created

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildConfig() 0 12 3
A get() 0 11 2
A all() 0 4 1
1
<?php
2
3
namespace FaizShukri\Quran\Supports;
4
5
class Config
6
{
7
    private $config;
8
9 87
    public function __construct(array $config = [])
10
    {
11 87
        $this->config = $this->buildConfig($config);
12 87
    }
13
14
    /**
15
     * Build a config array. Merge user defined config with our default config.
16
     *
17
     * @param array $config User defined config
18
     *
19
     * @return array New configuration array
20
     */
21 87
    private function buildConfig(array $config = [])
22
    {
23
        // Merge our config with user config
24 87
        $result = array_merge((include realpath(__DIR__.'/../../config/quran.php')), $config);
25
26
        // If function storage_path is exist (laravel), we update the path to laravel's storage path
27 87
        if (function_exists('storage_path') && php_sapi_name() !== 'cli') {
28
            $result['storage_path'] = storage_path('app'.DIRECTORY_SEPARATOR.$result['storage_path']);
29
        }
30
31 87
        return $result;
32
    }
33
34
    /**
35
     * Get the config variable.
36
     *
37
     * @param string $val Variable name
38
     *
39
     * @return array|string Variable value
40
     */
41 84
    public function get($val)
42
    {
43 84
        $configs = explode('.', $val);
44 84
        $first = $this->config[array_shift($configs)];
45
46 84
        foreach ($configs as $config) {
47 66
            $first = $first[$config];
48 84
        }
49
50 84
        return $first;
51
    }
52
53
    /**
54
     * Return all configurations.
55
     *
56
     * @return array
57
     */
58 3
    public function all()
59
    {
60 3
        return $this->config;
61
    }
62
}
63