Completed
Push — 2.x-dev ( d3c40b...4cc278 )
by Doug
13:11
created

BoxList::sort()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0092

Importance

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