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

Field   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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