Completed
Push — master ( 12d899...a33b7a )
by Avtandil
04:40
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
use Illuminate\Cache\CacheManager as Cache;
14
use Illuminate\Database\DatabaseManager as Database;
15
use Illuminate\Http\Request;
16
use Illuminate\Support\Collection;
17
use InvalidArgumentException;
18
19
class Config
20
{
21
    /**
22
     * Config data.
23
     *
24
     * @var array
25
     */
26
    protected $data;
27
28
    /**
29
     * Create a new MultiLang instance.
30
     *
31
     * @param string                               $environment
0 ignored issues
show
Bug introduced by
There is no parameter named $environment. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
32
     * @param array                                $config
0 ignored issues
show
Bug introduced by
There is no parameter named $config. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     * @param \Illuminate\Cache\CacheManager       $cache
0 ignored issues
show
Bug introduced by
There is no parameter named $cache. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     * @param \Illuminate\Database\DatabaseManager $db
0 ignored issues
show
Bug introduced by
There is no parameter named $db. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
35
     */
36 29
    public function __construct(array $data)
37
    {
38 29
        $this->data = $data;
39 29
    }
40
41 23
    public function get($key = null, $default = null)
42
    {
43 23
        $array = $this->data;
44
45 23
        if ($key === null) {
46 1
            return $array;
47
        }
48
49 22
        if (array_key_exists($key, $array)) {
50 9
            return $array[$key];
51
        }
52
53 22
        foreach (explode('.', $key) as $segment) {
54 22
            if (is_array($array) && array_key_exists($segment, $array)) {
55 22
                $array = $array[$segment];
56 22
            } else {
57
                return $default;
58
            }
59 22
        }
60
61 22
        return $array;
62
    }
63
64
65
}
66