Completed
Push — master ( 54b8d1...ceafd9 )
by Avtandil
02:36
created

Config::get()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 5
nop 2
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 6
rs 8.6737
c 0
b 0
f 0
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 27
    public function __construct(array $data)
28
    {
29 27
        $this->data = $data;
30 27
    }
31
32
    /**
33
     * Get config parameter
34
     *
35
     * @param string $key
36
     * @param mixed  $default
37
     * @return array|mixed|null
38
     */
39 21
    public function get($key = null, $default = null)
40
    {
41 21
        $array = $this->data;
42
43 21
        if ($key === null) {
44 1
            return $array;
45
        }
46
47 20
        if (array_key_exists($key, $array)) {
48 8
            return $array[$key];
49
        }
50
51 20
        foreach (explode('.', $key) as $segment) {
52 20
            if (is_array($array) && array_key_exists($segment, $array)) {
53 20
                $array = $array[$segment];
54
            } else {
55 20
                return $default;
56
            }
57
        }
58
59 20
        return $array;
60
    }
61
62
}
63