Completed
Branch master (0403bd)
by Doug
01:59
created
BoxList.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,11 +20,9 @@
 block discarded – undo
20 20
     public function compare($aBoxA, $aBoxB) {
21 21
       if ($aBoxB->getInnerVolume() > $aBoxA->getInnerVolume()) {
22 22
         return 1;
23
-      }
24
-      else if ($aBoxB->getInnerVolume() < $aBoxA->getInnerVolume()) {
23
+      } else if ($aBoxB->getInnerVolume() < $aBoxA->getInnerVolume()) {
25 24
         return -1;
26
-      }
27
-      else {
25
+      } else {
28 26
         return 0;
29 27
       }
30 28
     }
Please login to merge, or discard this patch.
PackedBoxList.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
         $boxVolume += $box->getBox()->getInnerVolume();
107 107
 
108 108
         /** @var Item $item */
109
-        foreach (clone $box->getItems() as $item ) {
109
+        foreach (clone $box->getItems() as $item) {
110 110
           $itemVolume += $item->getVolume();
111 111
         }
112 112
       }
Please login to merge, or discard this patch.
Packer.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         //Find best box of iteration, and remove packed items from unpacked list
145 145
         $bestBox = $packedBoxesIteration->top();
146 146
         $unPackedItems = $this->items->asArray();
147
-        foreach(clone $bestBox->getItems() as $packedItem) {
147
+        foreach (clone $bestBox->getItems() as $packedItem) {
148 148
           foreach ($unPackedItems as $unpackedKey => $unpackedItem) {
149 149
             if ($packedItem === $unpackedItem) {
150 150
               unset($unPackedItems[$unpackedKey]);
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     public function redistributeWeight(PackedBoxList $aPackedBoxes) {
174 174
 
175 175
       $targetWeight = $aPackedBoxes->getMeanWeight();
176
-      $this->logger->log(LogLevel::DEBUG,  "repacking for weight distribution, weight variance {$aPackedBoxes->getWeightVariance()}, target weight {$targetWeight}");
176
+      $this->logger->log(LogLevel::DEBUG, "repacking for weight distribution, weight variance {$aPackedBoxes->getWeightVariance()}, target weight {$targetWeight}");
177 177
 
178 178
       $packedBoxes = new PackedBoxList;
179 179
 
@@ -194,19 +194,19 @@  discard block
 block discarded – undo
194 194
 
195 195
       do { //Keep moving items from most overweight box to most underweight box
196 196
         $tryRepack = false;
197
-        $this->logger->log(LogLevel::DEBUG,  'boxes under/over target: ' . count($underWeightBoxes) . '/' . count($overWeightBoxes));
197
+        $this->logger->log(LogLevel::DEBUG, 'boxes under/over target: ' . count($underWeightBoxes) . '/' . count($overWeightBoxes));
198 198
 
199 199
         foreach ($underWeightBoxes as $u => $underWeightBox) {
200
-          $this->logger->log(LogLevel::DEBUG,  'Underweight Box ' . $u);
200
+          $this->logger->log(LogLevel::DEBUG, 'Underweight Box ' . $u);
201 201
           foreach ($overWeightBoxes as $o => $overWeightBox) {
202
-            $this->logger->log(LogLevel::DEBUG,  'Overweight Box ' . $o);
202
+            $this->logger->log(LogLevel::DEBUG, 'Overweight Box ' . $o);
203 203
             $overWeightBoxItems = $overWeightBox->getItems()->asArray();
204 204
 
205 205
             //For each item in the heavier box, try and move it to the lighter one
206 206
             foreach ($overWeightBoxItems as $oi => $overWeightBoxItem) {
207
-              $this->logger->log(LogLevel::DEBUG,  'Overweight Item ' . $oi);
207
+              $this->logger->log(LogLevel::DEBUG, 'Overweight Item ' . $oi);
208 208
               if ($underWeightBox->getWeight() + $overWeightBoxItem->getWeight() > $targetWeight) {
209
-                $this->logger->log(LogLevel::DEBUG,  'Skipping item for hindering weight distribution');
209
+                $this->logger->log(LogLevel::DEBUG, 'Skipping item for hindering weight distribution');
210 210
                 continue; //skip if moving this item would hinder rather than help weight distribution
211 211
               }
212 212
 
@@ -216,21 +216,21 @@  discard block
 block discarded – undo
216 216
               $newLighterBoxPacker = new Packer(); //we may need a bigger box
217 217
               $newLighterBoxPacker->setBoxes($this->boxes);
218 218
               $newLighterBoxPacker->setItems($newItemsForLighterBox);
219
-              $this->logger->log(LogLevel::INFO,  "[ATTEMPTING TO PACK LIGHTER BOX]");
219
+              $this->logger->log(LogLevel::INFO, "[ATTEMPTING TO PACK LIGHTER BOX]");
220 220
               $newLighterBox = $newLighterBoxPacker->doVolumePacking()->extract();
221 221
 
222 222
               if ($newLighterBox->getItems()->count() === $newItemsForLighterBox->count()) { //new item fits
223
-                $this->logger->log(LogLevel::DEBUG,  'New item fits');
223
+                $this->logger->log(LogLevel::DEBUG, 'New item fits');
224 224
                 unset($overWeightBoxItems[$oi]); //now packed in different box
225 225
 
226 226
                 $newHeavierBoxPacker = new Packer(); //we may be able to use a smaller box
227 227
                 $newHeavierBoxPacker->setBoxes($this->boxes);
228 228
                 $newHeavierBoxPacker->setItems($overWeightBoxItems);
229 229
 
230
-                $this->logger->log(LogLevel::INFO,  "[ATTEMPTING TO PACK HEAVIER BOX]");
230
+                $this->logger->log(LogLevel::INFO, "[ATTEMPTING TO PACK HEAVIER BOX]");
231 231
                 $newHeavierBoxes = $newHeavierBoxPacker->doVolumePacking();
232 232
                 if (count($newHeavierBoxes) > 1) { //found an edge case in packing algorithm that *increased* box count
233
-                  $this->logger->log(LogLevel::INFO,  "[REDISTRIBUTING WEIGHT] Abandoning redistribution, because new packing is less efficient than original");
233
+                  $this->logger->log(LogLevel::INFO, "[REDISTRIBUTING WEIGHT] Abandoning redistribution, because new packing is less efficient than original");
234 234
                   return $aPackedBoxes;
235 235
                 }
236 236
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * @return PackedBox packed box
263 263
      */
264 264
     public function packIntoBox(Box $aBox, ItemList $aItems) {
265
-      $this->logger->log(LogLevel::DEBUG,  "[EVALUATING BOX] {$aBox->getReference()}");
265
+      $this->logger->log(LogLevel::DEBUG, "[EVALUATING BOX] {$aBox->getReference()}");
266 266
 
267 267
       $packedItems = new ItemList;
268 268
       $remainingDepth = $aBox->getInnerDepth();
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
       $remainingLength = $aBox->getInnerLength();
272 272
 
273 273
       $layerWidth = $layerLength = $layerDepth = 0;
274
-      while(!$aItems->isEmpty()) {
274
+      while (!$aItems->isEmpty()) {
275 275
 
276 276
         $itemToPack = $aItems->top();
277 277
 
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
           continue;
281 281
         }
282 282
 
283
-        $this->logger->log(LogLevel::DEBUG,  "evaluating item {$itemToPack->getDescription()}");
284
-        $this->logger->log(LogLevel::DEBUG,  "remaining width: {$remainingWidth}, length: {$remainingLength}, depth: {$remainingDepth}");
285
-        $this->logger->log(LogLevel::DEBUG,  "layerWidth: {$layerWidth}, layerLength: {$layerLength}, layerDepth: {$layerDepth}");
283
+        $this->logger->log(LogLevel::DEBUG, "evaluating item {$itemToPack->getDescription()}");
284
+        $this->logger->log(LogLevel::DEBUG, "remaining width: {$remainingWidth}, length: {$remainingLength}, depth: {$remainingDepth}");
285
+        $this->logger->log(LogLevel::DEBUG, "layerWidth: {$layerWidth}, layerLength: {$layerLength}, layerDepth: {$layerDepth}");
286 286
 
287 287
         $itemWidth = $itemToPack->getWidth();
288 288
         $itemLength = $itemToPack->getLength();
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
           if ($fitsRotatedGap < 0 ||
299 299
               ($fitsSameGap >= 0 && $fitsSameGap <= $fitsRotatedGap) ||
300 300
               ($itemWidth <= $remainingWidth && !$aItems->isEmpty() && $aItems->top() == $itemToPack && $remainingLength >= 2 * $itemLength)) {
301
-            $this->logger->log(LogLevel::DEBUG,  "fits (better) unrotated");
301
+            $this->logger->log(LogLevel::DEBUG, "fits (better) unrotated");
302 302
             $remainingLength -= $itemLength;
303 303
             $layerLength += $itemLength;
304 304
             $layerWidth = max($itemWidth, $layerWidth);
305 305
           }
306 306
           else {
307
-            $this->logger->log(LogLevel::DEBUG,  "fits (better) rotated");
307
+            $this->logger->log(LogLevel::DEBUG, "fits (better) rotated");
308 308
             $remainingLength -= $itemWidth;
309 309
             $layerLength += $itemWidth;
310 310
             $layerWidth = max($itemLength, $layerWidth);
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 
314 314
           //allow items to be stacked in place within the same footprint up to current layerdepth
315 315
           $maxStackDepth = $layerDepth - $itemToPack->getDepth();
316
-          while(!$aItems->isEmpty()) {
316
+          while (!$aItems->isEmpty()) {
317 317
             $potentialStackItem = $aItems->top();
318 318
             if ($potentialStackItem->getDepth() <= $maxStackDepth &&
319 319
                 $potentialStackItem->getWeight() <= $remainingWeight &&
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
         }
331 331
         else {
332 332
           if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0 && $layerWidth > 0 && $layerLength > 0) {
333
-            $this->logger->log(LogLevel::DEBUG,  "No more fit in lengthwise, resetting for new row");
333
+            $this->logger->log(LogLevel::DEBUG, "No more fit in lengthwise, resetting for new row");
334 334
             $remainingLength += $layerLength;
335 335
             $remainingWidth -= $layerWidth;
336 336
             $layerWidth = $layerLength = 0;
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
           }
339 339
 
340 340
           if ($remainingLength < min($itemWidth, $itemLength) || $layerDepth == 0) {
341
-            $this->logger->log(LogLevel::DEBUG,  "doesn't fit on layer even when empty");
341
+            $this->logger->log(LogLevel::DEBUG, "doesn't fit on layer even when empty");
342 342
             $aItems->extract();
343 343
             continue;
344 344
           }
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
           $remainingDepth -= $layerDepth;
349 349
 
350 350
           $layerWidth = $layerLength = $layerDepth = 0;
351
-          $this->logger->log(LogLevel::DEBUG,  "doesn't fit, so starting next vertical layer");
351
+          $this->logger->log(LogLevel::DEBUG, "doesn't fit, so starting next vertical layer");
352 352
         }
353 353
       }
354
-      $this->logger->log(LogLevel::DEBUG,  "done with this box");
354
+      $this->logger->log(LogLevel::DEBUG, "done with this box");
355 355
       return new PackedBox($aBox, $packedItems, $remainingWidth, $remainingLength, $remainingDepth, $remainingWeight);
356 356
     }
357 357
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -60,14 +60,12 @@  discard block
 block discarded – undo
60 60
     public function setItems($aItems) {
61 61
       if ($aItems instanceof ItemList) {
62 62
         $this->items = clone $aItems;
63
-      }
64
-      else if (is_array($aItems)) {
63
+      } else if (is_array($aItems)) {
65 64
         $this->items = new ItemList();
66 65
         foreach ($aItems as $item) {
67 66
           $this->items->insert($item);
68 67
         }
69
-      }
70
-      else {
68
+      } else {
71 69
         throw new \RuntimeException('Not a valid list of items');
72 70
       }
73 71
     }
@@ -183,11 +181,9 @@  discard block
 block discarded – undo
183 181
         $boxWeight = $packedBox->getWeight();
184 182
         if ($boxWeight > $targetWeight) {
185 183
           $overWeightBoxes[] = $packedBox;
186
-        }
187
-        else if ($boxWeight < $targetWeight) {
184
+        } else if ($boxWeight < $targetWeight) {
188 185
           $underWeightBoxes[] = $packedBox;
189
-        }
190
-        else {
186
+        } else {
191 187
           $packedBoxes->insert($packedBox); //target weight, so we'll keep these
192 188
         }
193 189
       }
@@ -302,8 +298,7 @@  discard block
 block discarded – undo
302 298
             $remainingLength -= $itemLength;
303 299
             $layerLength += $itemLength;
304 300
             $layerWidth = max($itemWidth, $layerWidth);
305
-          }
306
-          else {
301
+          } else {
307 302
             $this->logger->log(LogLevel::DEBUG,  "fits (better) rotated");
308 303
             $remainingLength -= $itemWidth;
309 304
             $layerLength += $itemWidth;
@@ -322,13 +317,11 @@  discard block
 block discarded – undo
322 317
               $remainingWeight -= $potentialStackItem->getWeight();
323 318
               $maxStackDepth -= $potentialStackItem->getDepth();
324 319
               $packedItems->insert($aItems->extract());
325
-            }
326
-            else {
320
+            } else {
327 321
               break;
328 322
             }
329 323
           }
330
-        }
331
-        else {
324
+        } else {
332 325
           if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0 && $layerWidth > 0 && $layerLength > 0) {
333 326
             $this->logger->log(LogLevel::DEBUG,  "No more fit in lengthwise, resetting for new row");
334 327
             $remainingLength += $layerLength;
Please login to merge, or discard this patch.
ItemList.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,11 +20,9 @@
 block discarded – undo
20 20
     public function compare($aItemA, $aItemB) {
21 21
       if ($aItemA->getVolume() > $aItemB->getVolume()) {
22 22
         return 1;
23
-      }
24
-      else if ($aItemA->getVolume() < $aItemB->getVolume()) {
23
+      } else if ($aItemA->getVolume() < $aItemB->getVolume()) {
25 24
         return -1;
26
-      }
27
-      else {
25
+      } else {
28 26
         return 0;
29 27
       }
30 28
     }
Please login to merge, or discard this patch.