ProcessedFormReportBuilder::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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