Passed
Push — master ( 693b6d...992193 )
by Claudio
02:16
created

CallableAccess   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 6
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Budgegeria\IntlSort\Comparator;
6
7
use Budgegeria\IntlSort\Collator\Collator;
8
use Closure;
9
10
class CallableAccess implements Comparable
11
{
12
    /** @psalm-var Closure(mixed):string */
13
    private Closure $func;
14
15
    /** @psalm-param callable(mixed):string $func */
16 2
    public function __construct(private Collator $collator, callable $func)
17
    {
18 2
        $this->func = Closure::fromCallable($func);
19
    }
20
21 1
    public function compare(mixed $value, mixed $comparativeValue): int
22
    {
23 1
        return $this->collator->compare(
24 1
            ($this->func)($value),
25 1
            ($this->func)($comparativeValue),
26
        );
27
    }
28
}
29