Fields::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Dsn;
6
7
use Artack\Dsn\Field\FieldInterface;
8
9
class Fields
10
{
11
    private $fields = [];
12
13 14
    public function __construct(FieldInterface ...$fields)
14
    {
15 14
        foreach ($fields as $field) {
16 2
            $this->add($field);
17
        }
18 14
    }
19
20 10
    public function add(FieldInterface $field): void
21
    {
22 10
        $name = strtolower($field->getName());
23 10
        $this->fields[$name] = $field;
24 10
    }
25
26 4
    public function get(string $name): ?FieldInterface
27
    {
28 4
        $name = strtolower($name);
29 4
        if (!isset($this->fields[$name])) {
30 2
            return null;
31
        }
32
33 4
        return $this->fields[$name];
34
    }
35
36 10
    public function getAll(): iterable
37
    {
38 10
        yield from $this->fields;
39 10
    }
40
41 2
    public function getNames(): array
42
    {
43 2
        return array_keys($this->fields);
44
    }
45
46 2
    public function remove(string $name): void
47
    {
48 2
        unset($this->fields[strtolower($name)]);
49 2
    }
50
}
51