Completed
Push — master ( c83b47...38acfc )
by Avtandil
05:44
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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 8.6737
cc 6
eloc 12
nc 5
nop 2
crap 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
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
            } else {
57 22
                return $default;
58
            }
59
        }
60
61 22
        return $array;
62
    }
63
64
65
}
66