Passed
Push — master ( 60a2b8...a4571b )
by Chris
07:43
created

CollectionKernelBuilder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 29
dl 0
loc 74
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A withItems() 0 5 1
A withAccessors() 0 5 1
A withMapped() 0 5 1
A withJsonSerializer() 0 5 1
A build() 0 9 1
A withFactory() 0 5 1
A withPropertyResolver() 0 5 1
A withIdentifier() 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
use WebTheory\Collection\Resolution\PropertyResolver;
9
10
class CollectionKernelBuilder
11
{
12
    protected array $items = [];
13
14
    protected Closure $factory;
15
16
    protected array $accessors = [];
17
18
    protected ?string $identifier = null;
19
20
    protected bool $mapToIdentifier = false;
21
22
    protected JsonSerializerInterface $jsonSerializer;
23
24
    protected PropertyResolver $propertyResolver;
25
26
    public function withItems(array $items): self
27
    {
28
        $this->items = $items;
29
30
        return $this;
31
    }
32
33
    public function withFactory(callable $factory): self
34
    {
35
        $this->factory = $factory;
36
37
        return $this;
38
    }
39
40
    public function withAccessors(array $accessors): self
41
    {
42
        $this->accessors = $accessors;
43
44
        return $this;
45
    }
46
47
    public function withIdentifier(string $identifier): self
48
    {
49
        $this->identifier = $identifier;
50
51
        return $this;
52
    }
53
54
    public function withMapped(bool $map): self
55
    {
56
        $this->mapToIdentifier = $map;
57
58
        return $this;
59
    }
60
61
    public function withJsonSerializer(JsonSerializerInterface $jsonSerializer): self
62
    {
63
        $this->jsonSerializer = $jsonSerializer;
64
65
        return $this;
66
    }
67
68
    public function withPropertyResolver(PropertyResolver $propertyResolver): self
69
    {
70
        $this->propertyResolver = $propertyResolver;
71
72
        return $this;
73
    }
74
75
    public function build(): CollectionKernel
76
    {
77
        return new CollectionKernel(
78
            $this->items,
79
            $this->factory,
80
            $this->identifier,
81
            $this->accessors,
82
            $this->mapToIdentifier,
83
            $this->jsonSerializer,
84
        );
85
    }
86
}
87