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

CallableAccess::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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