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