ProcessedFormReportBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 53
ccs 16
cts 19
cp 0.8421
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A withProcessReport() 0 5 1
A withInputReport() 0 5 1
A withShieldReport() 0 5 1
A build() 0 6 1
1
<?php
2
3
namespace WebTheory\Saveyour\Report\Builder;
4
5
use WebTheory\Saveyour\Contracts\Report\Builder\ProcessedFormReportBuilderInterface;
6
use WebTheory\Saveyour\Contracts\Report\FormProcessReportInterface;
7
use WebTheory\Saveyour\Contracts\Report\FormShieldReportInterface;
8
use WebTheory\Saveyour\Contracts\Report\ProcessedFormReportInterface;
9
use WebTheory\Saveyour\Contracts\Report\ProcessedInputReportInterface;
10
use WebTheory\Saveyour\Report\ProcessedFormReport;
11
12
class ProcessedFormReportBuilder implements ProcessedFormReportBuilderInterface
13
{
14
    protected array $inputReports = [];
15
16
    protected array $processReports = [];
17
18
    protected FormShieldReportInterface $shieldReport;
19
20 45
    public function __construct(ProcessedFormReportInterface $previous = null)
21
    {
22 45
        if ($previous) {
23
            $this->inputReports = $previous->inputReports();
24
            $this->processReports = $previous->processReports();
25
            $this->shieldReport = $previous->shieldReport();
26
        }
27
    }
28
29
    /**
30
     * @return $this
31
     */
32 45
    public function withShieldReport(FormShieldReportInterface $report): ProcessedFormReportBuilderInterface
33
    {
34 45
        $this->shieldReport = $report;
35
36 45
        return $this;
37
    }
38
39
    /**
40
     * @return $this
41
     */
42 39
    public function withInputReport(string $input, ProcessedInputReportInterface $report): ProcessedFormReportBuilderInterface
43
    {
44 39
        $this->inputReports[$input] = $report;
45
46 39
        return $this;
47
    }
48
49
    /**
50
     * @return $this
51
     */
52 24
    public function withProcessReport(string $process, FormProcessReportInterface $report): ProcessedFormReportBuilderInterface
53
    {
54 24
        $this->processReports[$process] = $report;
55
56 24
        return $this;
57
    }
58
59 45
    public function build(): ProcessedFormReportInterface
60
    {
61 45
        return new ProcessedFormReport(
62 45
            $this->shieldReport,
63 45
            $this->inputReports,
64 45
            $this->processReports
65
        );
66
    }
67
}
68