Fields   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
ccs 20
cts 20
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A getNames() 0 3 1
A getAll() 0 3 1
A add() 0 4 1
A remove() 0 3 1
A __construct() 0 4 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