| Conditions | 12 |
| Paths | 9 |
| Total Lines | 61 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 168 | |||
| 169 | 42 | return PackedBox::fromPackedItemList($this->box, $this->getPackedItemList($layers)); |
|
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * During packing, it is quite possible that layers have been created that aren't physically stable |
||
| 174 | * i.e. they overhang the ones below. |
||
| 175 | * |
||
| 176 | * This function reorders them so that the ones with the greatest surface area are placed at the bottom |
||
| 177 | * |
||
| 178 | * @param PackedLayer[] $oldLayers |
||
| 179 | * @return PackedLayer[] |
||
| 180 | */ |
||
| 181 | 42 | private function stabiliseLayers(array $oldLayers) |
|
| 182 | { |
||
| 183 | 42 | if ($this->singlePassMode || $this->hasConstrainedItems) { // constraints include position, so cannot change |
|
| 184 | 32 | return $oldLayers; |
|
| 185 | } |
||
| 186 | |||
| 187 | 42 | $stabiliser = new LayerStabiliser(); |
|
| 188 | |||
| 189 | 42 | return $stabiliser->stabilise($oldLayers); |
|
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Swap back width/length of the packed items to match orientation of the box if needed. |
||
| 194 | * |
||
| 195 | * @param PackedLayer[] $oldLayers |
||
| 196 | */ |
||
| 197 | 42 | private function correctLayerRotation(array $oldLayers, $boxWidth) |
|
| 198 | { |
||
| 199 | 42 | if ($this->box->getInnerWidth() === $boxWidth) { |
|
| 200 | 42 | return $oldLayers; |
|
| 201 | } |
||
| 202 | |||
| 203 | 4 | $newLayers = []; |
|
| 204 | 4 | foreach ($oldLayers as $originalLayer) { |
|
| 205 | 4 | $newLayer = new PackedLayer(); |
|
| 206 | 4 | foreach ($originalLayer->getItems() as $item) { |
|
| 207 | 4 | $packedItem = new PackedItem($item->getItem(), $item->getY(), $item->getX(), $item->getZ(), $item->getLength(), $item->getWidth(), $item->getDepth()); |
|
| 208 | 4 | $newLayer->insert($packedItem); |
|
| 209 | } |
||
| 210 | 4 | $newLayers[] = $newLayer; |
|
| 211 | } |
||
| 212 | |||
| 213 | 4 | return $newLayers; |
|
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Generate a single list of items packed. |
||
| 218 | * @param PackedLayer[] $layers |
||
| 219 | */ |
||
| 220 | 42 | private function getPackedItemList(array $layers) |
|
| 221 | { |
||
| 222 | 42 | $packedItemList = new PackedItemList(); |
|
| 223 | 42 | foreach ($layers as $layer) { |
|
| 224 | 42 | foreach ($layer->getItems() as $packedItem) { |
|
| 225 | 42 | $packedItemList->insert($packedItem); |
|
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | 42 | return $packedItemList; |
|
| 247 |