ObjectPropertyComparator::__construct()   A
last analyzed

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 187
    public function __construct(PropertyResolverInterface $propertyResolver, string $property)
15
    {
16 187
        $this->propertyResolver = $propertyResolver;
17 187
        $this->property = $property;
18
    }
19
20 187
    public function comparison(object $a, object $b): int
21
    {
22 187
        return $this->resolveValue($a) <=> $this->resolveValue($b);
23
    }
24
}
25