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