FieldLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\ContentType;
6
7
class FieldLoader
8
{
9
    private $fieldRegistry;
10
    private $fields = [];
11
12
    public function __construct(FieldRegistry $fieldRegistry)
13
    {
14
        $this->fieldRegistry = $fieldRegistry;
15
    }
16
17
    public function load(string $type, FieldOptions $options): Field
18
    {
19
        $hash = md5(serialize($options)) . $type;
20
21
        if (isset($this->fields[$hash])) {
22
            return $this->fields[$hash];
23
        }
24
25
        $field = $this->fieldRegistry->get($type);
26
        $field = new Field($field, $options);
27
28
        $this->fields[$hash] = $field;
29
30
        return $field;
31
    }
32
}
33