Permalink
Browse files

Update comparisons to use spaceship operator

  • Loading branch information...
dvdoug committed Aug 19, 2017
1 parent 60e8fb9 commit 53d2201b6509a0fa893c7f677f855c04c0d37052
Showing with 2 additions and 16 deletions.
  1. +1 −8 src/ItemList.php
  2. +1 −8 src/PackedItemList.php
View
@@ -29,14 +29,7 @@ public function compare($itemA, $itemB): int
{
$itemAVolume = $itemA->getWidth() * $itemA->getLength() * $itemA->getDepth();
$itemBVolume = $itemB->getWidth() * $itemB->getLength() * $itemB->getDepth();
if ($itemAVolume > $itemBVolume) {
return 1;
} elseif ($itemAVolume < $itemBVolume) {
return -1;
} else {
return $itemA->getWeight() - $itemB->getWeight();
}
return ($itemAVolume <=> $itemBVolume) ?: ($itemA->getWeight() - $itemB->getWeight());
}
/**
View
@@ -29,14 +29,7 @@ public function compare($itemA, $itemB): int
{
$itemAVolume = $itemA->getItem()->getWidth() * $itemA->getItem()->getLength() * $itemA->getItem()->getDepth();
$itemBVolume = $itemB->getItem()->getWidth() * $itemB->getItem()->getLength() * $itemB->getItem()->getDepth();
if ($itemAVolume > $itemBVolume) {
return 1;
} elseif ($itemAVolume < $itemBVolume) {
return -1;
} else {
return $itemA->getItem()->getWeight() - $itemB->getItem()->getWeight();
}
return ($itemAVolume <=> $itemBVolume) ?: ($itemA->getItem()->getWeight() - $itemB->getItem()->getWeight());
}
/**

0 comments on commit 53d2201

Please sign in to comment.