Passed
Push — 2.x-dev ( e5166d...a75e6c )
by Doug
02:18
created

BoxList::compare()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem).
4
 *
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker;
9
10
/**
11
 * List of boxes available to put items into, ordered by volume.
12
 *
13
 * @author Doug Wright
14
 */
15
class BoxList extends \SplMinHeap
16
{
17
    /**
18
     * Compare elements in order to place them correctly in the heap while sifting up.
19
     *
20
     * @see \SplMinHeap::compare()
21
     *
22
     * @param Box $boxA
23
     * @param Box $boxB
24
     *
25
     * @return int
26
     */
27 8
    public function compare($boxA, $boxB)
28
    {
29 8
        if ($boxB->getInnerVolume() > $boxA->getInnerVolume()) {
30 8
            return 1;
31 3
        } elseif ($boxB->getInnerVolume() < $boxA->getInnerVolume()) {
32 1
            return -1;
33
        } else {
34 3
            return 0;
35
        }
36
    }
37
}
38