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

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B get() 0 22 6
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