FieldRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getField() 0 9 3
A add() 0 3 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
}