Completed
Push — master ( 8112b0...bcd086 )
by Faiz
02:39
created

Config::buildConfig()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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