| Total Complexity | 6 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class ValueObject implements Comparable |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Collator |
||
| 14 | */ |
||
| 15 | private $collator; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $methodOrPropertyName; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var bool |
||
| 24 | */ |
||
| 25 | private $isProperty; |
||
| 26 | |||
| 27 | 26 | public function __construct(Collator $collator, string $name, bool $isProperty) |
|
| 32 | 26 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritDoc} |
||
| 36 | */ |
||
| 37 | 24 | public function compare($value, $comparativeValue): int |
|
| 38 | { |
||
| 39 | try { |
||
| 40 | 24 | $compared = $this->collator->compare( |
|
| 41 | 24 | $this->callAccessor($value), |
|
| 42 | 24 | $this->callAccessor($comparativeValue) |
|
| 43 | ); |
||
| 44 | |||
| 45 | 22 | if ($this->collator->getErrorCode() !== 0) { |
|
| 46 | 22 | throw IntlSortException::errorOnSort($this->collator->getErrorMessage()); |
|
| 47 | } |
||
| 48 | 4 | } catch (\IntlException $e) { |
|
| 49 | 2 | throw IntlSortException::errorOnSort($e->getMessage()); |
|
| 50 | } |
||
| 51 | |||
| 52 | 20 | return $compared; |
|
| 53 | } |
||
| 54 | |||
| 55 | 24 | private function callAccessor(object $valueObject) : string |
|
| 62 | } |
||
| 63 | } |