Passed
Push — master ( f8b808...2b4fc7 )
by Chris
36:39
created

MappedSorter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
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 14
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveValue() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace WebTheory\Collection\Sorting;
4
5
use WebTheory\Collection\Contracts\CollectionSorterInterface;
6
use WebTheory\Collection\Contracts\PropertyResolverInterface;
7
8
class MappedSorter extends PropertySorter implements CollectionSorterInterface
9
{
10
    protected array $map = [];
11
12 51
    public function __construct(PropertyResolverInterface $resolver, string $property, array $map)
13
    {
14 51
        parent::__construct($resolver, $property);
15
16 51
        $this->map = $map;
17
    }
18
19 48
    protected function resolveValue(object $item): int
20
    {
21 48
        return $this->map[parent::resolveValue($item)] ?? 0;
22
    }
23
}
24