ValueObject   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 4
b 0
f 0
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A callAccessor() 0 7 2
A compare() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Budgegeria\IntlSort\Comparator;
6
7
use Budgegeria\IntlSort\Collator\Collator;
8
9
class ValueObject implements Comparable
10
{
11 26
    public function __construct(private Collator $collator, private string $methodOrPropertyName, private bool $isProperty)
12
    {
13 26
    }
14
15 24
    public function compare(mixed $value, mixed $comparativeValue): int
16
    {
17 24
        return $this->collator->compare(
18 24
            $this->callAccessor((object) $value),
19 24
            $this->callAccessor((object) $comparativeValue),
20 24
        );
21
    }
22
23 24
    private function callAccessor(object $valueObject): mixed
24
    {
25 24
        if ($this->isProperty) {
26 12
            return $valueObject->{$this->methodOrPropertyName};
27
        }
28
29 12
        return $valueObject->{$this->methodOrPropertyName}();
30
    }
31
}
32