Passed
Push — master ( afdec1...60a2b8 )
by Chris
07:28
created

AutoKeyedMap::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace WebTheory\Collection\Driver;
4
5
use WebTheory\Collection\Contracts\ArrayDriverInterface;
6
use WebTheory\Collection\Contracts\ObjectComparatorInterface;
7
use WebTheory\Collection\Contracts\PropertyResolverInterface;
8
use WebTheory\Collection\Driver\Abstracts\AbstractArrayDriver;
9
use WebTheory\Collection\Resolution\Abstracts\ResolvesPropertyValueTrait;
10
11
class AutoKeyedMap extends AbstractArrayDriver implements ArrayDriverInterface
12
{
13
    use ResolvesPropertyValueTrait;
14
15 33
    public function __construct(
16
        string $property,
17
        PropertyResolverInterface $propertyResolver,
18
        ObjectComparatorInterface $objectComparator
19
    ) {
20 33
        $this->property = $property;
21 33
        $this->propertyResolver = $propertyResolver;
22 33
        $this->objectComparator = $objectComparator;
23
    }
24
25 33
    public function insert(array &$array, object $item, $locator = null): bool
26
    {
27 33
        if ($this->arrayContainsObject($array, $item)) {
28 3
            return false;
29
        }
30
31 33
        $array[$this->resolveValue($item)] = $item;
32
33 33
        return true;
34
    }
35
}
36