DefaultsHandler::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms;
6
7
use Enjoys\Forms\Interfaces\DefaultsHandlerInterface;
8
9
class DefaultsHandler implements DefaultsHandlerInterface
10
{
11
    private array $defaults = [];
12
13 95
    public function __construct(array $data = [])
14
    {
15 95
        $this->setData($data);
16
    }
17
18 95
    public function setData(array $data = []): void
19
    {
20 95
        $this->defaults = $data;
21
    }
22
23
    /**
24
     *
25
     * @return mixed
26
     */
27 4
    public function getDefaults(): mixed
28
    {
29 4
        return $this->get();
30
    }
31
32
    /**
33
     *
34
     * @return mixed
35
     */
36 95
    public function getValue(?string $param): mixed
37
    {
38 95
        return $this->get($param);
39
    }
40
41
42 95
    private function get(?string $param = null): mixed
43
    {
44 95
        if ($param === null) {
45 4
            return $this->defaults;
46
        }
47 95
        return \getValueByIndexPath($param, $this->defaults);
48
    }
49
}
50