DefaultsHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 9
c 0
b 0
f 0
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 6 2
A getValue() 0 3 1
A getDefaults() 0 3 1
A setData() 0 3 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