Conditions | 3 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
59 | 22 | public static function compare($boxA, $boxB): int |
|
60 | { |
||
61 | 22 | $boxAVolume = $boxA->getInnerWidth() * $boxA->getInnerLength() * $boxA->getInnerDepth(); |
|
62 | 22 | $boxBVolume = $boxB->getInnerWidth() * $boxB->getInnerLength() * $boxB->getInnerDepth(); |
|
63 | |||
64 | 22 | $volumeDecider = $boxAVolume <=> $boxBVolume; // try smallest box first |
|
65 | |||
66 | 22 | if ($volumeDecider !== 0) { |
|
67 | 18 | return $volumeDecider; |
|
68 | } |
||
69 | |||
70 | 4 | $emptyWeightDecider = $boxA->getEmptyWeight() <=> $boxB->getEmptyWeight(); // with smallest empty weight |
|
71 | 4 | if ($emptyWeightDecider !== 0) { |
|
72 | 4 | return $emptyWeightDecider; |
|
73 | } |
||
74 | |||
75 | // maximum weight capacity as fallback decider |
||
76 | 1 | return ($boxA->getMaxWeight() - $boxA->getEmptyWeight()) <=> ($boxB->getMaxWeight() - $boxB->getEmptyWeight()); |
|
77 | } |
||
79 |