AbstractField   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Test Coverage

Coverage 65.38%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 139
ccs 34
cts 52
cp 0.6538
rs 10
c 0
b 0
f 0
wmc 21

21 Methods

Rating   Name   Duplication   Size   Complexity  
A defineMustAwait() 0 3 1
A inspect() 0 3 1
A compose() 0 3 1
A validate() 0 3 1
A getUpdatedValue() 0 3 1
A defineDataFormatter() 0 3 1
A mustAwait() 0 3 1
A getPresetValue() 0 3 1
A defineRequestVar() 0 3 1
A getRequestVar() 0 3 1
A requestVarPresent() 0 3 1
A defineFormField() 0 3 1
A defineValidator() 0 3 1
A isPermittedToProcess() 0 3 1
A definePermissionProcessStatus() 0 3 1
A process() 0 3 1
A render() 0 3 1
A defineDataManager() 0 3 1
A __construct() 0 7 1
A createFormFieldController() 0 10 1
A getFormField() 0 3 1
1
<?php
2
3
namespace WebTheory\Saveyour\Controller\Abstracts;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use WebTheory\Saveyour\Contracts\Controller\FormFieldControllerInterface;
7
use WebTheory\Saveyour\Contracts\Data\FieldDataManagerInterface;
8
use WebTheory\Saveyour\Contracts\Field\FormFieldInterface;
9
use WebTheory\Saveyour\Contracts\Formatting\DataFormatterInterface;
10
use WebTheory\Saveyour\Contracts\Report\ProcessedFieldReportInterface;
11
use WebTheory\Saveyour\Contracts\Report\ValidationReportInterface;
12
use WebTheory\Saveyour\Controller\FormFieldController;
13
use WebTheory\Saveyour\Validation\Validator;
14
15
abstract class AbstractField implements FormFieldControllerInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected string $__requestVar;
21
22
    /**
23
     * @var bool
24
     */
25
    protected bool $__isPermittedToProcess = true;
26
27
    /**
28
     * @var array<int,string>
29
     */
30
    protected array $__mustAwait = [];
31
32
    protected FormFieldControllerInterface $__coreController;
33
34 12
    public function __construct(string $requestVar, array $mustAwait = [], $processingEnabled = true)
35
    {
36 12
        $this->__requestVar = $requestVar;
37 12
        $this->__mustAwait = $mustAwait;
38 12
        $this->__isPermittedToProcess = $processingEnabled;
39
40 12
        $this->__coreController = $this->createFormFieldController();
41
    }
42
43
    /**
44
     * Get the value of requestVar
45
     *
46
     * @return string
47
     */
48 3
    public function getRequestVar(): string
49
    {
50 3
        return $this->__coreController->getRequestVar();
51
    }
52
53
    public function getFormField(): ?FormFieldInterface
54
    {
55
        return $this->__coreController->getFormField();
56
    }
57
58
    public function requestVarPresent(ServerRequestInterface $request): bool
59
    {
60
        return $this->__coreController->requestVarPresent($request);
61
    }
62
63
    public function inspect($value): ValidationReportInterface
64
    {
65
        return $this->__coreController->inspect($value);
66
    }
67
68
    public function validate($value): bool
69
    {
70
        return $this->__coreController->validate($value);
71
    }
72
73
    public function getPresetValue(ServerRequestInterface $request)
74
    {
75
        return $this->__coreController->getPresetValue($request);
76
    }
77
78
    public function getUpdatedValue(ServerRequestInterface $request): ?array
79
    {
80
        return $this->__coreController->getUpdatedValue($request);
81
    }
82
83 3
    public function mustAwait(): array
84
    {
85 3
        return $this->__coreController->mustAwait();
86
    }
87
88
    public function render(ServerRequestInterface $request): string
89
    {
90
        return $this->__coreController->render($request);
91
    }
92
93
    public function compose(ServerRequestInterface $request): FormFieldInterface
94
    {
95
        return $this->__coreController->compose($request);
96
    }
97
98 6
    public function isPermittedToProcess(): bool
99
    {
100 6
        return $this->__coreController->isPermittedToProcess();
101
    }
102
103
    public function process(ServerRequestInterface $request): ProcessedFieldReportInterface
104
    {
105
        return $this->__coreController->process($request);
106
    }
107
108 12
    protected function createFormFieldController(): FormFieldControllerInterface
109
    {
110 12
        return new FormFieldController(
111 12
            $this->defineRequestVar(),
112 12
            $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...
113 12
            $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...
114 12
            $this->defineValidator(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineValidator() targeting WebTheory\Saveyour\Contr...ield::defineValidator() 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...
115 12
            $this->defineDataFormatter(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->defineDataFormatter() targeting WebTheory\Saveyour\Contr...::defineDataFormatter() 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...
116 12
            $this->definePermissionProcessStatus(),
117 12
            $this->defineMustAwait(),
118
        );
119
    }
120
121 12
    protected function defineRequestVar(): string
122
    {
123 12
        return $this->__requestVar;
124
    }
125
126 12
    protected function defineFormField(): ?FormFieldInterface
127
    {
128 12
        return null;
129
    }
130
131 12
    protected function defineDataManager(): ?FieldDataManagerInterface
132
    {
133 12
        return null;
134
    }
135
136 12
    protected function defineDataFormatter(): ?DataFormatterInterface
137
    {
138 12
        return null;
139
    }
140
141 12
    protected function defineValidator(): ?Validator
142
    {
143 12
        return null;
144
    }
145
146 12
    protected function definePermissionProcessStatus(): ?bool
147
    {
148 12
        return $this->__isPermittedToProcess;
149
    }
150
151 12
    protected function defineMustAwait(): ?array
152
    {
153 12
        return $this->__mustAwait;
154
    }
155
}
156