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) |
|
|
|
|
84
|
|
|
$this->resolved[$methodName] = $resolver->$methodName($this->options); |
85
|
|
|
|
86
|
|
|
return $this->resolved[$methodName]; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.