Passed
Push — master ( ccf673...70274a )
by Zing
03:57
created

Config::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Zing\LaravelSms\Support;
4
5
use ArrayAccess;
6
7
/**
8
 * Class Config.
9
 */
10
class Config implements ArrayAccess
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $config;
16
17
    /**
18
     * Config constructor.
19
     *
20
     * @param array $config
21
     */
22 21
    public function __construct(array $config = [])
23
    {
24 21
        $this->config = $config;
25 21
    }
26
27
    /**
28
     * Get an item from an array using "dot" notation.
29
     *
30
     * @param string $key
31
     * @param mixed  $default
32
     *
33
     * @return mixed
34
     */
35 23
    public function get($key, $default = null)
36
    {
37 23
        $config = $this->config;
38
39 23
        if (isset($config[$key])) {
40 12
            return $config[$key];
41
        }
42
43 19
        if (strpos($key, '.') === false) {
44 19
            return $default;
45
        }
46
47 2
        foreach (explode('.', $key) as $segment) {
48 2
            if (! is_array($config) || ! array_key_exists($segment, $config)) {
49
                return $default;
50
            }
51 2
            $config = $config[$segment];
52
        }
53
54 2
        return $config;
55
    }
56
57 1
    public function offsetExists($offset)
58
    {
59 1
        return array_key_exists($offset, $this->config);
60
    }
61
62 4
    public function offsetGet($offset)
63
    {
64 4
        return $this->get($offset);
65
    }
66
67 1
    public function offsetSet($offset, $value)
68
    {
69 1
        if (isset($this->config[$offset])) {
70 1
            $this->config[$offset] = $value;
71
        }
72 1
    }
73
74 1
    public function offsetUnset($offset)
75
    {
76 1
        if (isset($this->config[$offset])) {
77 1
            unset($this->config[$offset]);
78
        }
79 1
    }
80
}
81