| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 13 | 19 | public function compare(Box $boxA, Box $boxB): int |
|
| 14 | { |
||
| 15 | 19 | $boxAVolume = $boxA->getInnerWidth() * $boxA->getInnerLength() * $boxA->getInnerDepth(); |
|
| 16 | 19 | $boxBVolume = $boxB->getInnerWidth() * $boxB->getInnerLength() * $boxB->getInnerDepth(); |
|
| 17 | |||
| 18 | 19 | $volumeDecider = $boxAVolume <=> $boxBVolume; // try smallest box first |
|
| 19 | |||
| 20 | 19 | if ($volumeDecider !== 0) { |
|
| 21 | 16 | return $volumeDecider; |
|
| 22 | } |
||
| 23 | |||
| 24 | 3 | $emptyWeightDecider = $boxA->getEmptyWeight() <=> $boxB->getEmptyWeight(); // with smallest empty weight |
|
| 25 | 3 | if ($emptyWeightDecider !== 0) { |
|
| 26 | 2 | return $emptyWeightDecider; |
|
| 27 | } |
||
| 28 | |||
| 29 | // maximum weight capacity as fallback decider |
||
| 30 | 1 | return ($boxA->getMaxWeight() - $boxA->getEmptyWeight()) <=> ($boxB->getMaxWeight() - $boxB->getEmptyWeight()); |
|
| 31 | } |
||
| 33 |