Completed
Pull Request — master (#9)
by ANTHONIUS
02:55
created

Config::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Core\Config;
15
16
use Dotfiles\Core\Exceptions\InvalidArgumentException;
17
18
/**
19
 * Class Config.
20
 */
21
class Config implements \ArrayAccess
22
{
23
    private $configs = array();
24
25
    public function all()
26
    {
27
        return $this->configs;
28
    }
29
30
    public function get($name)
31
    {
32
        if (!array_key_exists($name, $this->configs)) {
33
            throw new InvalidArgumentException('Config key "'.$name.'" not exists.');
34
        }
35
36
        return $this->configs[$name];
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function offsetExists($offset)
43
    {
44
        return isset($this->configs[$offset]);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function offsetGet($offset)
51
    {
52
        return $this->configs[$offset];
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function offsetSet($offset, $value): void
59
    {
60
        $this->configs[$offset] = $value;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function offsetUnset($offset): void
67
    {
68
        unset($this->configs[$offset]);
69
    }
70
71
    public function set($name, $value): self
72
    {
73
        $this->configs[$name] = $value;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param array $configs
80
     */
81
    public function setConfigs(array $configs): void
82
    {
83
        $this->configs = $configs;
84
    }
85
}
86