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