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

ObjectPropertyComparator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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