Test Failed
Push — master ( 6eea59...bfd094 )
by Chris
31:05
created

CollectionKernelBuilder   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 9
eloc 30
c 0
b 0
f 0
dl 0
loc 103
ccs 26
cts 32
cp 0.8125
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A withItems() 0 5 1
A withGenerator() 0 5 1
A withMapped() 0 5 1
A withJsonSerializer() 0 5 1
A thatIsNotMapped() 0 5 1
A build() 0 9 1
A thatIsMapped() 0 5 1
A withIdentifier() 0 5 1
A withAccessors() 0 5 1
1
<?php
2
3
namespace WebTheory\Collection\Kernel\Builder;
4
5
use Closure;
6
use WebTheory\Collection\Contracts\JsonSerializerInterface;
7
use WebTheory\Collection\Kernel\CollectionKernel;
8
9
class CollectionKernelBuilder
10
{
11
    protected array $items = [];
12
13
    protected Closure $generator;
14
15
    protected array $accessors = [];
16
17
    protected ?string $identifier = null;
18
19
    protected bool $isMap = false;
20
21
    protected ?JsonSerializerInterface $jsonSerializer = null;
22
23
    /**
24
     * @return $this
25
     */
26 98
    public function withItems(array $items): CollectionKernelBuilder
27
    {
28 98
        $this->items = $items;
29
30 98
        return $this;
31
    }
32
33
    /**
34
     * @return $this
35
     */
36 98
    public function withGenerator(Closure $generator): CollectionKernelBuilder
37
    {
38 98
        $this->generator = $generator;
39
40 98
        return $this;
41
    }
42
43
    /**
44
     * @return $this
45
     */
46
    public function withAccessors(array $accessors): CollectionKernelBuilder
47
    {
48
        $this->accessors = $accessors;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return $this
55
     */
56 90
    public function withIdentifier(?string $identifier): CollectionKernelBuilder
57
    {
58 90
        $this->identifier = $identifier;
59
60 90
        return $this;
61
    }
62
63
    /**
64
     * @return $this
65
     */
66 18
    public function thatIsMapped(): CollectionKernelBuilder
67
    {
68 18
        $this->isMap = true;
69
70 18
        return $this;
71
    }
72
73
    /**
74
     * @return $this
75
     */
76 80
    public function thatIsNotMapped(): CollectionKernelBuilder
77
    {
78 80
        $this->isMap = false;
79
80 80
        return $this;
81
    }
82
83
    /**
84
     * @return $this
85
     */
86 52
    public function withMapped(bool $isMap): CollectionKernelBuilder
87
    {
88 52
        $this->isMap = $isMap;
89
90 52
        return $this;
91
    }
92
93
    /**
94
     * @return $this
95
     */
96
    public function withJsonSerializer(JsonSerializerInterface $jsonSerializer): CollectionKernelBuilder
97
    {
98
        $this->jsonSerializer = $jsonSerializer;
99
100
        return $this;
101
    }
102
103 98
    public function build(): CollectionKernel
104
    {
105 98
        return new CollectionKernel(
106 98
            $this->items,
107 98
            $this->generator,
108 98
            $this->identifier,
109 98
            $this->accessors,
110 98
            $this->isMap,
111 98
            $this->jsonSerializer,
112 98
        );
113
    }
114
}
115