ObjectPropertyComparator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A comparison() 0 3 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