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