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

BoxList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

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