FieldRegistry::getField()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
namespace rtens\domin\delivery;
3
4
use rtens\domin\Parameter;
5
6
class FieldRegistry {
7
8
    /** @var array|Field[] */
9
    private $fields = [];
10
11
    /**
12
     * @param Parameter $parameter
13
     * @return Field
14
     * @throws \Exception
15
     */
16
    public function getField(Parameter $parameter) {
17
        foreach ($this->fields as $field) {
18
            if ($field->handles($parameter)) {
19
                return $field;
20
            }
21
        }
22
23
        throw new \Exception("No field found to handle [$parameter]");
24
    }
25
26
    public function add(Field $field) {
27
        $this->fields[] = $field;
28
    }
29
}