Test Failed
Push — master ( 2c2c87...ed1c51 )
by Chris
25:05 queued 37s
created

SettingsFieldCollection::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Leonidas\Library\Admin\Page\SettingsField;
4
5
use Leonidas\Contracts\Admin\Components\SettingsFieldCollectionInterface;
6
use Leonidas\Contracts\Admin\Components\SettingsFieldInterface;
7
8
class SettingsFieldCollection implements SettingsFieldCollectionInterface
9
{
10
    /**
11
     * @var SettingsFieldInterface[]
12
     */
13
    protected array $fields;
14
15
    public function __construct(SettingsFieldInterface ...$fields)
16
    {
17
        array_map([$this, 'add'], $fields);
18
    }
19
20
    public function add(SettingsFieldInterface $field)
21
    {
22
        $this->fields[$field->getId()] = $field;
23
    }
24
25
    public function get(string $field): SettingsFieldInterface
26
    {
27
        return $this->fields[$field];
28
    }
29
30
    public function remove(string $field)
31
    {
32
        unset($this->fields[$field]);
33
    }
34
35
    public function has(string $field): bool
36
    {
37
        return isset($this->fields[$field]);
38
    }
39
40
    public function all(): array
41
    {
42
        return $this->fields;
43
    }
44
}
45