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

BoxList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 8 3
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