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

Field::getInnerField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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