Passed
Branch 1.0 (690a53)
by Vladimir
07:08
created

Config::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
6
7
use JsonSerializable;
8
use FondBot\Helpers\Arr;
9
10
class Config implements JsonSerializable
11
{
12
    private $items;
13
14 3
    public function __construct(array $items)
15
    {
16 3
        $this->items = $items;
17 3
    }
18
19
    /**
20
     * Get option.
21
     *
22
     * @param string $key
23
     * @param null   $default
24
     *
25
     * @return mixed
26
     */
27 3
    public function get(string $key, $default = null)
28
    {
29 3
        return Arr::get($this->items, $key, $default);
30
    }
31
32
    /**
33
     * Set option.
34
     *
35
     * @param string $key
36
     * @param mixed  $value
37
     */
38 1
    public function set(string $key, $value): void
39
    {
40 1
        Arr::set($this->items, $key, $value);
41 1
    }
42
43
    /**
44
     * Determine if option exists.
45
     *
46
     * @param string $key
47
     *
48
     * @return bool
49
     */
50 1
    public function has(string $key): bool
51
    {
52 1
        return Arr::has($this->items, [$key]);
53
    }
54
55
    /**
56
     * Specify data which should be serialized to JSON.
57
     * @link  http://php.net/manual/en/jsonserializable.jsonserialize.php
58
     * @return mixed data which can be serialized by <b>json_encode</b>,
59
     * which is a value of any type other than a resource.
60
     * @since 5.4.0
61
     */
62 1
    public function jsonSerialize(): array
63
    {
64 1
        return $this->items;
65
    }
66
}
67