DefaultPackedBoxSorter::compare()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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