Passed
Push — master ( 2f6942...d6d802 )
by Chris
28:11
created

getObjectComparator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace WebTheory\Collection\Kernel\Factory;
4
5
use WebTheory\Collection\Access\IdentifiableItemList;
6
use WebTheory\Collection\Access\PropertyMap;
7
use WebTheory\Collection\Access\StandardList;
8
use WebTheory\Collection\Access\StandardMap;
9
use WebTheory\Collection\Comparison\CollectionComparator;
10
use WebTheory\Collection\Comparison\ObjectIdComparator;
11
use WebTheory\Collection\Comparison\ObjectPropertyComparator;
12
use WebTheory\Collection\Contracts\ArrayDriverInterface;
13
use WebTheory\Collection\Contracts\CollectionComparatorInterface;
14
use WebTheory\Collection\Contracts\ObjectComparatorInterface;
15
use WebTheory\Collection\Contracts\PropertyResolverInterface;
16
use WebTheory\Collection\Resolution\PropertyResolver;
17
18
class CollectionKernelSubsystemFactory
19
{
20
    protected ?string $identifier;
21
22
    protected array $accessors;
23
24
    protected bool $isMap;
25
26
    protected PropertyResolverInterface $propertyResolver;
27
28
    protected ObjectComparatorInterface $objectComparator;
29
30 309
    public function __construct(?string $identifier, array $accessors, bool $isMap)
31
    {
32 309
        $this->identifier = $identifier;
33 309
        $this->accessors = $accessors;
34 309
        $this->isMap = $isMap;
35
36 309
        $this->propertyResolver = new PropertyResolver($accessors);
37 309
        $this->objectComparator = $identifier
38 309
            ? new ObjectPropertyComparator($this->propertyResolver, $identifier)
39 132
            : new ObjectIdComparator();
40
    }
41
42 309
    public function getPropertyResolver(): PropertyResolverInterface
43
    {
44 309
        return $this->propertyResolver;
45
    }
46
47 309
    public function getObjectComparator(): ObjectComparatorInterface
48
    {
49 309
        return $this->objectComparator;
50
    }
51
52 309
    public function getCollectionComparator(): CollectionComparatorInterface
53
    {
54 309
        return new CollectionComparator($this->objectComparator);
55
    }
56
57 309
    public function getArrayDriver(): ArrayDriverInterface
58
    {
59 309
        if ($this->identifier && $this->isMap) {
60 69
            $driver = new PropertyMap(
61 69
                $this->identifier,
62 69
                $this->propertyResolver,
63 69
                $this->objectComparator
64
            );
65 309
        } elseif ($this->identifier) {
66 309
            $driver = new IdentifiableItemList(
67 309
                $this->identifier,
68 309
                $this->propertyResolver,
69 309
                $this->objectComparator
70
            );
71 132
        } elseif ($this->isMap) {
72 42
            $driver = new StandardMap($this->objectComparator);
73
        } else {
74 90
            $driver = new StandardList($this->objectComparator);
75
        }
76
77 309
        return $driver;
78
    }
79
}
80