Passed
Push — 3.x ( 071761...f78397 )
by Doug
03:06
created

DefaultPackedBoxSorter::compare()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 4
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem).
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace DVDoug\BoxPacker;
10
11
class DefaultPackedBoxSorter implements PackedBoxSorter
12
{
13 13
    public function compare(PackedBox $boxA, PackedBox $boxB): int
14
    {
15 13
        $choice = $boxB->getItems()->count() <=> $boxA->getItems()->count();
16
17 13
        if ($choice === 0) {
18 10
            $choice = $boxB->getVolumeUtilisation() <=> $boxA->getVolumeUtilisation();
19
        }
20 13
        if ($choice === 0) {
21 9
            $choice = $boxB->getUsedVolume() <=> $boxA->getUsedVolume();
22
        }
23
24 13
        return $choice;
25
    }
26
}
27