Conditions | 7 |
Paths | 7 |
Total Lines | 30 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 7.0119 |
Changes | 0 |
1 | <?php |
||
27 | 13 | public function compare($boxA, $boxB) |
|
28 | { |
||
29 | 13 | $boxAVolume = $boxA->getInnerWidth() * $boxA->getInnerLength() * $boxA->getInnerDepth(); |
|
30 | 13 | $boxBVolume = $boxB->getInnerWidth() * $boxB->getInnerLength() * $boxB->getInnerDepth(); |
|
31 | |||
32 | // try smallest box first |
||
33 | 13 | if ($boxBVolume > $boxAVolume) { |
|
34 | 12 | return 1; |
|
35 | } |
||
36 | 4 | if ($boxAVolume > $boxBVolume) { |
|
37 | 1 | return -1; |
|
38 | } |
||
39 | |||
40 | // smallest empty weight |
||
41 | 4 | if ($boxA->getEmptyWeight() > $boxB->getEmptyWeight()) { |
|
42 | 1 | return 1; |
|
43 | } |
||
44 | 4 | if ($boxB->getEmptyWeight() > $boxA->getEmptyWeight()) { |
|
45 | 1 | return -1; |
|
46 | } |
||
47 | |||
48 | // maximum weight capacity as fallback decider |
||
49 | 4 | if (($boxA->getMaxWeight() - $boxA->getEmptyWeight()) > ($boxB->getMaxWeight() - $boxB->getEmptyWeight())) { |
|
50 | 1 | return -1; |
|
51 | } |
||
52 | 3 | if (($boxB->getMaxWeight() - $boxB->getEmptyWeight()) > ($boxA->getMaxWeight() - $boxA->getEmptyWeight())) { |
|
53 | return 1; |
||
54 | } |
||
55 | |||
56 | 3 | return 0; |
|
57 | } |
||
59 |