ValueObject::callAccessor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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