elements = $elements; } public function sort(): array { if (!$this->comparator) { throw new \LogicException('Comparator is not set'); } uasort($this->elements, [$this->comparator, 'compare']); return $this->elements; } /** * @param ComparatorInterface $comparator */ public function setComparator(ComparatorInterface $comparator) { $this->comparator = $comparator; } }