FieldLoader::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 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