Completed
Push — master ( 894211...021184 )
by Daniel
04:29
created

Field   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOptions() 0 4 1
A getFormType() 0 4 1
A getFormOptions() 0 4 1
A getViewType() 0 4 1
A getViewOptions() 0 4 1
A getStorageOptions() 0 4 1
A getStorageType() 0 4 1
A getInnerField() 0 4 1
A getResolver() 0 11 2
A resolve() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\ContentType;
6
7
use Psi\Component\ContentType\OptionsResolver\FieldOptionsResolver;
8
9
class Field
10
{
11
    private $resolved;
12
    private $resolver;
13
    private $options;
14
    private $field;
15
16
    public function __construct(FieldInterface $field, array $options)
17
    {
18
        $this->field = $field;
19
        $this->options = $options;
20
    }
21
22
    public function getOptions(): array
23
    {
24
        return $this->resolve('resolve');
25
    }
26
27
    public function getFormType(): string
28
    {
29
        return $this->field->getFormType();
30
    }
31
32
    public function getFormOptions(): array
33
    {
34
        return $this->resolve('resolveFormOptions');
35
    }
36
37
    public function getViewType(): string
38
    {
39
        return $this->field->getViewType();
40
    }
41
42
    public function getViewOptions(): array
43
    {
44
        return $this->resolve('resolveViewOptions');
45
    }
46
47
    public function getStorageOptions(): array
48
    {
49
        return $this->resolve('resolveStorageOptions');
50
    }
51
52
    public function getStorageType(): string
53
    {
54
        return $this->field->getStorageType();
55
    }
56
57
    public function getInnerField()
58
    {
59
        return $this->field;
60
    }
61
62
    private function getResolver(): FieldOptionsResolver
63
    {
64
        if ($this->resolver) {
65
            return $this->resolver;
66
        }
67
68
        $this->resolver = new FieldOptionsResolver();
69
        $this->field->configureOptions($this->resolver);
70
71
        return $this->resolver;
72
    }
73
74
    private function resolve(string $methodName)
75
    {
76
        if (isset($this->resolved[$methodName])) {
77
            return $this->resolved[$methodName];
78
        }
79
80
        $resolver = $this->getResolver();
81
82
        $this->resolved[$methodName] = $resolver->$methodName($this->options);
83
84
        return $this->resolved[$methodName];
85
    }
86
}
87