Completed
Push — master ( 998e37...ce7c33 )
by Faiz
01:51
created

Config::buildConfig()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
crap 3
1
<?php
2
3
namespace FaizShukri\Quran\Supports;
4
5
class Config
6
{
7
    private $config;
8
9 57
    public function __construct(array $config = [])
10
    {
11 57
        $this->config = $this->buildConfig($config);
12 57
    }
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 57
    private function buildConfig(array $config = [])
22
    {
23
        // Merge our config with user config
24 57
        $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 57
        if (function_exists('storage_path') && php_sapi_name() !== 'cli')
28 57
            $result['storage_path'] = storage_path('app' . DIRECTORY_SEPARATOR . $result['storage_path']);
29
30 57
        return $result;
31
    }
32
33
    /**
34
     * Get the config variable
35
     *
36
     * @param string $val Variable name
37
     *
38
     * @return mixed Variable value
39
     */
40 57
    public function get($val)
41
    {
42 57
        return $this->config[$val];
43
    }
44
}