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

ObjectPropertyComparator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 16
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getComparisonFunction() 0 6 1
1
<?php
2
3
namespace WebTheory\Collection\Comparison;
4
5
use WebTheory\Collection\Comparison\Abstracts\AbstractObjectComparator;
6
use WebTheory\Collection\Contracts\ObjectComparatorInterface;
7
use WebTheory\Collection\Contracts\PropertyResolverInterface;
8
use WebTheory\Collection\Resolution\Abstracts\ResolvesPropertyValueTrait;
9
10
class ObjectPropertyComparator extends AbstractObjectComparator implements ObjectComparatorInterface
11
{
12
    use ResolvesPropertyValueTrait;
13
14 309
    public function __construct(PropertyResolverInterface $propertyResolver, string $property)
15
    {
16 309
        $this->propertyResolver = $propertyResolver;
17 309
        $this->property = $property;
18
    }
19
20 309
    protected function getComparisonFunction(): callable
21
    {
22
        return fn (
23
            $a,
24
            $b
25 309
        ): int => $this->resolveValue($a) <=> $this->resolveValue($b);
26
    }
27
}
28