DefaultItemSorter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 8
c 2
b 0
f 2
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 12 3
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 DefaultItemSorter implements ItemSorter
13 100
{
14
    public function compare(Item $itemA, Item $itemB): int
15 100
    {
16 100
        $volumeDecider = $itemB->getWidth() * $itemB->getLength() * $itemB->getDepth() <=> $itemA->getWidth() * $itemA->getLength() * $itemA->getDepth();
17 60
        if ($volumeDecider !== 0) {
18
            return $volumeDecider;
19 86
        }
20 86
        $weightDecider = $itemB->getWeight() <=> $itemA->getWeight();
21 4
        if ($weightDecider !== 0) {
22
            return $weightDecider;
23
        }
24 82
25
        return $itemA->getDescription() <=> $itemB->getDescription();
26
    }
27
}
28