Skip to content

Commit

Permalink
Try and fix PHP5
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 25, 2020
1 parent dbb0e69 commit 9ceec92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/OrientatedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function getBestOrientation(

// prefer leaving room for next item in current row
if ($nextItems->count()) {
$nextItemFitA = count($this->getPossibleOrientations($nextItems->top(), $a, $orientationAWidthLeft, $lengthLeft, $depthLeft, $x, $y, $z, $prevPackedItemList));
$nextItemFitB = count($this->getPossibleOrientations($nextItems->top(), $b, $orientationBWidthLeft, $lengthLeft, $depthLeft, $x, $y, $z, $prevPackedItemList));
$nextItemFitA = $this->getPossibleOrientations($nextItems->top(), $a, $orientationAWidthLeft, $lengthLeft, $depthLeft, $x, $y, $z, $prevPackedItemList);
$nextItemFitB = $this->getPossibleOrientations($nextItems->top(), $b, $orientationBWidthLeft, $lengthLeft, $depthLeft, $x, $y, $z, $prevPackedItemList);
if ($nextItemFitA && !$nextItemFitB) {
return -1;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ protected function calculateAdditionalItemsPackedWithThisOrientation(

if (!isset(static::$lookaheadCache[$cacheKey])) {
$tempBox = new WorkingVolume($originalWidthLeft - $prevItem->getWidth(), $currentRowLength, $depthLeft, PHP_INT_MAX);
$tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
$tempPacker = new VolumePacker($tempBox, $itemsToPack);
$tempPacker->setLookAheadMode(true);
$remainingRowPacked = $tempPacker->pack();
/** @var PackedItem $packedItem */
Expand All @@ -365,7 +365,7 @@ protected function calculateAdditionalItemsPackedWithThisOrientation(
}

$tempBox = new WorkingVolume($originalWidthLeft, $originalLengthLeft - $currentRowLength, $depthLeft, PHP_INT_MAX);
$tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
$tempPacker = new VolumePacker($tempBox, $itemsToPack);
$tempPacker->setLookAheadMode(true);
$nextRowsPacked = $tempPacker->pack();
/** @var PackedItem $packedItem */
Expand Down
4 changes: 4 additions & 0 deletions src/PackedBoxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function compare($boxA, $boxB)
$choice = $boxB->getWeight() - $boxA->getWeight();
}

if ($choice == 0) {
$choice = PHP_MAJOR_VERSION > 5 ? -1 : 1;
}

return $choice;

}
Expand Down
3 changes: 3 additions & 0 deletions src/Packer.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ private static function compare(PackedBox $boxA, PackedBox $boxB)
if ($choice == 0) {
$choice = $boxB->getUsedVolume() - $boxA->getUsedVolume();
}
if ($choice == 0) {
$choice = PHP_MAJOR_VERSION > 5 ? -1 : 1;
}

return $choice;
}
Expand Down

0 comments on commit 9ceec92

Please sign in to comment.