Passed
Pull Request — master (#15)
by Kevin
17:16
created

Config::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Task;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
final class Config
9
{
10
    private $data = [];
11
12
    /**
13
     * @param mixed $value
14
     */
15
    public function set(string $name, $value): self
16
    {
17
        $this->data[$name] = $value;
18
19
        return $this;
20
    }
21
22
    /**
23
     * @param mixed $default
24
     *
25
     * @return mixed
26
     */
27
    public function get(string $name, $default = null)
28
    {
29
        return $this->data[$name] ?? $default;
30
    }
31
32
    public function all(): array
33
    {
34
        return $this->data;
35
    }
36
37
    public function humanized(): array
38
    {
39
        $ret = [];
40
41
        foreach ($this->data as $key => $value) {
42
            switch (true) {
43
                case \is_bool($value):
44
                    $value = $value ? 'yes' : 'no';
45
46
                    break;
47
48
                case \is_scalar($value):
49
                    break;
50
51
                case \is_object($value):
52
                    $value = \sprintf('(%s)', \get_class($value));
53
54
                    break;
55
56
                default:
57
                    $value = \sprintf('(%s)', \gettype($value));
58
            }
59
60
            $ret[$key] = $value;
61
        }
62
63
        return $ret;
64
    }
65
}
66