ProcessedFieldReportBuilder::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\ProcessedFieldReportBuilderInterface;
6
use WebTheory\Saveyour\Contracts\Report\ProcessedFieldReportInterface;
7
use WebTheory\Saveyour\Report\ProcessedFieldReport;
8
9
class ProcessedFieldReportBuilder implements ProcessedFieldReportBuilderInterface
10
{
11
    protected $sanitizedInputValue = null;
12
13
    protected bool $updateAttempted = false;
14
15
    protected bool $updateSuccessful = false;
16
17 6
    public function __construct(?ProcessedFieldReportInterface $previous = null)
18
    {
19 6
        if ($previous) {
20
            $this->sanitizedInputValue = $previous->sanitizedInputValue();
21
            $this->updateAttempted = $previous->updateAttempted();
22
            $this->updateSuccessful = $previous->updateSuccessful();
23
        }
24
    }
25
26
    /**
27
     * @return $this
28
     */
29 6
    public function withSanitizedInputValue($value): ProcessedFieldReportBuilder
30
    {
31 6
        $this->sanitizedInputValue = $value;
32
33 6
        return $this;
34
    }
35
36
    /**
37
     * @return $this
38
     */
39 5
    public function withUpdateAttempted(bool $result): ProcessedFieldReportBuilder
40
    {
41 5
        $this->updateAttempted = $result;
42
43 5
        return $this;
44
    }
45
46
    /**
47
     * @return $this
48
     */
49 5
    public function withUpdateSuccessful(bool $result): ProcessedFieldReportBuilder
50
    {
51 5
        $this->updateSuccessful = $result;
52
53 5
        return $this;
54
    }
55
56 6
    public function build(): ProcessedFieldReportInterface
57
    {
58 6
        return new ProcessedFieldReport(
59 6
            $this->sanitizedInputValue,
60 6
            $this->updateAttempted,
61 6
            $this->updateSuccessful
62
        );
63
    }
64
}
65