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

AutoKeyedMap   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A insert() 0 9 2
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