Passed
Pull Request — master (#9)
by ANTHONIUS
02:18
created

Parameters   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 56
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A offsetUnset() 0 3 1
A all() 0 3 1
A offsetGet() 0 3 1
A get() 0 7 2
A offsetExists() 0 3 1
A setConfigs() 0 3 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\DI;
15
16
use Dotfiles\Core\Exceptions\InvalidArgumentException;
17
18
/**
19
 * Provide parameters during runtime.
20
 */
21
class Parameters 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('Parameters 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
    /**
72
     * @param array $configs
73
     */
74
    public function setConfigs(array $configs): void
75
    {
76
        $this->configs = $configs;
77
    }
78
}
79