Completed
Push — master ( b4e56c...1b6c56 )
by Avtandil
04:39
created

Config::get()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.0163

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 12
c 1
b 0
f 1
nc 5
nop 2
dl 0
loc 22
ccs 12
cts 13
cp 0.9231
crap 6.0163
rs 8.6737
1
<?php
2
/*
3
 * This file is part of the Laravel MultiLang package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\LaravelMultiLang;
12
13
class Config
14
{
15
    /**
16
     * Config data.
17
     *
18
     * @var array
19
     */
20
    protected $data;
21
22
    /**
23
     * Create a new MultiLang config instance.
24
     *
25
     * @param array $data
26
     */
27 30
    public function __construct(array $data)
28
    {
29 30
        $this->data = $data;
30 30
    }
31
32
    /**
33
     * Get config parameter
34
     *
35
     * @param string $key
36
     * @param mixed  $default
37
     * @return array|mixed|null
38
     */
39 24
    public function get($key = null, $default = null)
40
    {
41 24
        $array = $this->data;
42
43 24
        if ($key === null) {
44 1
            return $array;
45
        }
46
47 23
        if (array_key_exists($key, $array)) {
48 9
            return $array[$key];
49
        }
50
51 23
        foreach (explode('.', $key) as $segment) {
52 23
            if (is_array($array) && array_key_exists($segment, $array)) {
53 23
                $array = $array[$segment];
54 23
            } else {
55
                return $default;
56
            }
57 23
        }
58
59 23
        return $array;
60
    }
61
62
}
63