Completed
Pull Request — master (#39)
by Daniel
05:19
created

Field::getOptions()   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
    private function getResolver(): FieldOptionsResolver
58
    {
59
        if ($this->resolver) {
60
            return $this->resolver;
61
        }
62
63
        $this->resolver = new FieldOptionsResolver();
64
        $this->field->configureOptions($this->resolver);
65
66
        return $this->resolver;
67
    }
68
69
    private function resolve(string $methodName)
70
    {
71
        if (isset($this->resolved[$methodName])) {
72
            return $this->resolved[$methodName];
73
        }
74
75
        $resolver = $this->getResolver();
76
77
        // $resolver->resolve[Form|View|Storage]Options(array $options)
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
        $this->resolved[$methodName] = $resolver->$methodName($this->options);
79
80
        return $this->resolved[$methodName];
81
    }
82
}
83