AbstractForm   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 64
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A html() 0 3 1
A shield() 0 3 1
A data() 0 7 1
A manager() 0 6 1
A controllers() 0 3 1
A process() 0 3 1
A processors() 0 3 1
1
<?php
2
3
namespace WebTheory\Saveyour\Controller\Abstracts;
4
5
use ArrayIterator;
6
use IteratorAggregate;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Traversable;
9
use WebTheory\Saveyour\Contracts\Auth\FormShieldInterface;
10
use WebTheory\Saveyour\Contracts\Controller\FormFieldControllerInterface;
11
use WebTheory\Saveyour\Contracts\Controller\FormInterface;
12
use WebTheory\Saveyour\Contracts\Controller\FormSubmissionManagerInterface;
13
use WebTheory\Saveyour\Contracts\Processor\FormDataProcessorInterface;
14
use WebTheory\Saveyour\Contracts\Report\ProcessedFormReportInterface;
15
use WebTheory\Saveyour\Controller\FormSubmissionManager;
16
17
abstract class AbstractForm implements FormInterface, IteratorAggregate
18
{
19
    public function data(ServerRequestInterface $request): array
20
    {
21
        return [
22
            'method' => $this->method(),
23
            'action' => $this->action(),
24
            'checks' => $this->checks(),
25
            'fields' => $this->fields(),
26
        ];
27
    }
28
29
    public function process(ServerRequestInterface $request): ProcessedFormReportInterface
30
    {
31
        return $this->manager()->process($request);
32
    }
33
34
    public function getIterator(): Traversable
35
    {
36
        return new ArrayIterator($this->fields());
0 ignored issues
show
Bug introduced by
$this->fields() of type iterable is incompatible with the type array expected by parameter $array of ArrayIterator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        return new ArrayIterator(/** @scrutinizer ignore-type */ $this->fields());
Loading history...
37
    }
38
39
    public function html(ServerRequestInterface $request): ?string
40
    {
41
        return null;
42
    }
43
44
    protected function manager(): FormSubmissionManagerInterface
45
    {
46
        return new FormSubmissionManager(
47
            $this->controllers(),
48
            $this->processors(),
49
            $this->shield()
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->shield() targeting WebTheory\Saveyour\Contr...\AbstractForm::shield() 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...
50
        );
51
    }
52
53
    protected function shield(): ?FormShieldInterface
54
    {
55
        return null;
56
    }
57
58
    /**
59
     * @return array<string, FormFieldControllerInterface>
60
     */
61
    protected function controllers(): array
62
    {
63
        return [];
64
    }
65
66
    /**
67
     * @return array<string,FormDataProcessorInterface>
68
     */
69
    protected function processors(): array
70
    {
71
        return [];
72
    }
73
74
    abstract protected function action(): string;
75
76
    abstract protected function method(): string;
77
78
    abstract protected function checks(): string;
79
80
    abstract protected function fields(): iterable;
81
}
82