Example #1
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     /** @var int $comp */
     $comp = $this->id <=> $object->id;
     return $comp;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function equals($object) : bool
 {
     if ($this === $object) {
         return true;
     }
     if (!Validate::areSameType($this, $object)) {
         return false;
     }
     return $this->uuid->equals($object->uuid);
 }
Example #3
0
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     $comp = strnatcmp($this->username(), $object->username());
     if ($comp > 0) {
         return 1;
     }
     if ($comp < 0) {
         return -1;
     }
     return 0;
 }
Example #4
0
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     $thisVal = $this->value();
     $thatVal = $object->value();
     if ($thisVal > $thatVal) {
         return 1;
     }
     if ($thisVal < $thatVal) {
         return -1;
     }
     return 0;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     $thisVal = $this->value;
     $thatVal = $object->value;
     $thisParts = explode('/', $thisVal);
     $thatParts = explode('/', $thatVal);
     if (count($thisParts) > 1 && count($thatParts) > 1) {
         return $this->compareParts($thisParts, $thatParts);
     } elseif (count($thisParts) > 1) {
         return 1;
     } elseif (count($thatParts) > 1) {
         return -1;
     }
     $strComp = strnatcmp($thisVal, $thatVal);
     /** @var int $comp */
     $comp = $strComp <=> 0;
     return $comp;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     $strComp = strnatcmp($this->toString(), $object->toString());
     /** @var int $comp */
     $comp = $strComp <=> 0;
     return $comp;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     if ($this->hour > $object->hour) {
         return 1;
     }
     if ($this->hour < $object->hour) {
         return -1;
     }
     if ($this->minute > $object->minute) {
         return 1;
     }
     if ($this->minute < $object->minute) {
         return -1;
     }
     if ($this->second > $object->second) {
         return 1;
     }
     if ($this->second < $object->second) {
         return -1;
     }
     return 0;
 }
Example #8
0
 /**
  * @dataProvider invalidSameTypeProvider
  */
 public function test_that_are_same_type_returns_false_for_invalid_value($value1, $value2)
 {
     $this->assertFalse(Validate::areSameType($value1, $value2));
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     if ($this->year > $object->year) {
         return 1;
     }
     if ($this->year < $object->year) {
         return -1;
     }
     if ($this->month > $object->month) {
         return 1;
     }
     if ($this->month < $object->month) {
         return -1;
     }
     if ($this->day > $object->day) {
         return 1;
     }
     if ($this->day < $object->day) {
         return -1;
     }
     return 0;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function compareTo($object) : int
 {
     if ($this === $object) {
         return 0;
     }
     assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class));
     $thisStamp = $this->timestamp();
     $thatStamp = $object->timestamp();
     if ($thisStamp > $thatStamp) {
         return 1;
     }
     if ($thisStamp < $thatStamp) {
         return -1;
     }
     return $this->timezone->compareTo($object->timezone);
 }