Completed
Pull Request — master (#44)
by Korotkov
01:42
created

Container::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Jagepard <[email protected]">
7
 * @copyright Copyright (c) 2019, Jagepard
8
 * @license   https://mit-license.org/ MIT
9
 */
10
11
namespace Rudra\Container;
12
13
use Rudra\Container\Interfaces\ContainerInterface;
14
15
class Container implements ContainerInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $data = [];
21
22
    /**
23
     * @param string|null $key
24
     * @return array
25
     */
26
    public function get(string $key = null)
27
    {
28
        return empty($key) ? $this->data : $this->data[$key];
29
    }
30
31
    /**
32
     * @param array $data
33
     */
34
    public function set(array $data): void
35
    {
36
        $this->data = array_merge($data, $this->data);
37
    }
38
39
    /**
40
     * @param string $key
41
     * @return bool
42
     */
43
    public function has(string $key): bool
44
    {
45
        return array_key_exists($key, $this->data);
46
    }
47
}
48