Passed
Push — master ( 042e95...d37488 )
by Chris
02:46
created

AbstractField::defineRequestVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace WebTheory\Saveyour\Controllers;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Respect\Validation\Validatable;
7
use WebTheory\Saveyour\Contracts\DataTransformerInterface;
8
use WebTheory\Saveyour\Contracts\FieldDataManagerInterface;
9
use WebTheory\Saveyour\Contracts\FieldOperationCacheInterface;
10
use WebTheory\Saveyour\Contracts\FormFieldControllerInterface;
11
use WebTheory\Saveyour\Contracts\FormFieldInterface;
12
13
abstract class AbstractField implements FormFieldControllerInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $__requestVar;
19
20
    /**
21
     * @var bool
22
     */
23
    protected $__processingDisabled = false;
24
25
    /**
26
     * @var array
27
     */
28
    protected $__mustAwait = [];
29
30
    /**
31
     * @var FormFieldControllerInterface
32
     */
33
    protected $__coreController;
34
35
    /**
36
     *
37
     */
38 3
    public function __construct(string $requestVar, array $mustAwait = [], $processingDisabled = false)
39
    {
40 3
        $this->__requestVar = $requestVar;
41 3
        $this->__mustAwait = $mustAwait;
42 3
        $this->__processingDisabled = $processingDisabled;
43
44 3
        $this->__coreController = $this->createFormFieldController();
45 3
    }
46
47
    /**
48
     * Get the value of requestVar
49
     *
50
     * @return string
51
     */
52 3
    public function getRequestVar(): string
53
    {
54 3
        return $this->__coreController->getRequestVar();
55
    }
56
57
    /**
58
     *
59
     */
60
    public function getFormField(): ?FormFieldInterface
61
    {
62
        return $this->__coreController->getFormField();
63
    }
64
65
    /**
66
     *
67
     */
68
    public function getPresetValue(ServerRequestInterface $request)
69
    {
70
        return $this->__coreController->getPresetValue($request);
71
    }
72
73
    /**
74
     *
75
     */
76
    public function mustAwait(): array
77
    {
78
        return $this->__coreController->mustAwait();
79
    }
80
81
    /**
82
     *
83
     */
84
    public function render(ServerRequestInterface $request): ?FormFieldInterface
85
    {
86
        return $this->__coreController->render($request);
87
    }
88
89
    /**
90
     *
91
     */
92
    public function process(ServerRequestInterface $request): FieldOperationCacheInterface
93
    {
94
        return $this->__coreController->process($request);
95
    }
96
97
    /**
98
     * @return Validatable[]
99
     */
100
    public function getRules(): array
101
    {
102
        return $this->__coreController->getRules();
103
    }
104
105
    /**
106
     * @return Validatable
107
     */
108
    public function getRule(string $rule): Validatable
109
    {
110
        return $this->__coreController->getRule($rule);
111
    }
112
113
    /**
114
     * @return callable[]
115
     */
116
    public function getFilters(): array
117
    {
118
        return $this->__coreController->getFilters();
119
    }
120
121
    /**
122
     * @return bool|mixed
123
     */
124
    public function filterInput($input)
125
    {
126
        return $this->__coreController->filterInput($input);
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public function getViolations(): array
133
    {
134
        return $this->__coreController->getViolations();
135
    }
136
137
    /**
138
     *
139
     */
140 3
    protected function createFormFieldController(): FormFieldControllerInterface
141
    {
142 3
        return new BaseFormFieldController(
143 3
            $this->defineRequestVar(),
144 3
            $this->defineFormField(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineFormField() targeting WebTheory\Saveyour\Contr...ield::defineFormField() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
145 3
            $this->defineDataManager(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineDataManager() targeting WebTheory\Saveyour\Contr...ld::defineDataManager() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
146 3
            $this->defineDataTransformer(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineDataTransformer() targeting WebTheory\Saveyour\Contr...defineDataTransformer() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
147 3
            $this->defineFilters(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineFilters() targeting WebTheory\Saveyour\Contr...tField::defineFilters() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
148 3
            $this->defineRules(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineRules() targeting WebTheory\Saveyour\Contr...actField::defineRules() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
149 3
            $this->defineEscaper(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineEscaper() targeting WebTheory\Saveyour\Contr...tField::defineEscaper() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
150 3
            $this->defineProcessingDisabled(),
151 3
            $this->defineMustAwait()
152
        );
153
    }
154
155
    /**
156
     *
157
     */
158 3
    protected function defineRequestVar(): string
159
    {
160 3
        return $this->__requestVar;
161
    }
162
163
    /**
164
     *
165
     */
166 3
    protected function defineFormField(): ?FormFieldInterface
167
    {
168 3
        return null;
169
    }
170
171
    /**
172
     *
173
     */
174 3
    protected function defineDataManager(): ?FieldDataManagerInterface
175
    {
176 3
        return null;
177
    }
178
179
    /**
180
     *
181
     */
182 3
    protected function defineDataTransformer(): ?DataTransformerInterface
183
    {
184 3
        return null;
185
    }
186
187
    /**
188
     *
189
     */
190 3
    protected function defineFilters(): ?array
191
    {
192 3
        return null;
193
    }
194
195
    /**
196
     *
197
     */
198 3
    protected function defineRules(): ?array
199
    {
200 3
        return null;
201
    }
202
203
    /**
204
     *
205
     */
206 3
    protected function defineEscaper(): ?callable
207
    {
208 3
        return null;
209
    }
210
211
    /**
212
     *
213
     */
214 3
    protected function defineProcessingDisabled(): ?bool
215
    {
216 3
        return $this->__processingDisabled;
217
    }
218
219
    /**
220
     *
221
     */
222 3
    protected function defineMustAwait(): ?array
223
    {
224 3
        return $this->__mustAwait;
225
    }
226
}
227