/** * @inheritdoc */ public function compare(IComparable $other) : int { if (!$other instanceof static) { throw new LogicException('You cannot compare sheep with the goat.'); } return IntervalUtils::numberCmp($this->getTimestamp(), $other->getTimestamp()); }
/** * @inheritdoc */ public function compare(IComparable $other) : int { if (!$other instanceof static) { throw new LogicException('You cannot compare sheep with the goat.'); } return $this->int <=> $other->getInt(); }
/** * @param IComparable $five * @param IComparable $six */ public function assertForComparison(IComparable $five, IComparable $six) { Assert::true($five->isLessThan($six)); Assert::true($five->isLessThanOrEqual($six)); Assert::false($six->isLessThan($five)); Assert::false($six->isLessThanOrEqual($five)); Assert::false($five->isEqual($six)); Assert::false($six->isEqual($five)); }
/** * @inheritdoc */ public function compare(IComparable $other) : int { if (!$other instanceof self) { // intentionally self throw new LogicException('You cannot compare sheep with the goat.'); } $comparison = $this->element->compare($other->element); if ($comparison === 0) { if ($this->state === $other->state) { return 0; } return $this->isOpened() ? -1 : 1; } return $comparison; }