Conditions | 9 |
Paths | 7 |
Total Lines | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 9 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 61 | public function compare(mixed $value, mixed $comparativeValue): int |
|
22 | { |
||
23 | 61 | if (($comparativeValue === null || $value === null) && $this->config->getNullableSort() === Configuration::NULL_VALUES_LAST) { |
|
24 | 1 | return $comparativeValue <=> $value; |
|
25 | } |
||
26 | |||
27 | 61 | if (($comparativeValue === null || $value === null) && $this->config->getNullableSort() === Configuration::NULL_VALUES_FIRST) { |
|
28 | 2 | return Configuration::NULL_VALUES_FIRST; |
|
29 | } |
||
30 | |||
31 | try { |
||
32 | 61 | $compared = $this->collator->compare((string) $value, (string) $comparativeValue); |
|
33 | |||
34 | 59 | assert(is_int($compared)); |
|
35 | |||
36 | 59 | if ($this->collator->getErrorCode() !== 0) { |
|
37 | 59 | throw IntlSortException::errorOnSort($this->collator->getErrorMessage()); |
|
38 | } |
||
39 | 4 | } catch (IntlException $e) { |
|
40 | 2 | throw IntlSortException::errorOnSort($e->getMessage()); |
|
41 | } |
||
42 | |||
43 | 57 | return $compared; |
|
44 | } |
||
46 |