Passed
Push — behat ( a74de5...4872f1 )
by Doug
02:39
created

OrientatedItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 2
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
/**
12
 * An item to be packed.
13
 *
14
 * @author Doug Wright
15
 */
16
class OrientatedItem
17
{
18
    /**
19
     * @var Item
20
     */
21
    protected $item;
22
23
    /**
24
     * @var int
25
     */
26
    protected $width;
27
28
    /**
29
     * @var int
30
     */
31
    protected $length;
32
33
    /**
34
     * @var int
35
     */
36
    protected $depth;
37
38
    /**
39
     * Constructor.
40
     *
41
     * @param Item $item
42
     * @param int  $width
43
     * @param int  $length
44
     * @param int  $depth
45
     */
46
    public function __construct(Item $item, int $width, int $length, int $depth)
47
    {
48
        $this->item = $item;
49
        $this->width = $width;
50
        $this->length = $length;
51
        $this->depth = $depth;
52
    }
53
54
    /**
55
     * Item.
56
     *
57
     * @return Item
58
     */
59
    public function getItem(): Item
60
    {
61
        return $this->item;
62
    }
63
64
    /**
65
     * Item width in mm in it's packed orientation.
66
     *
67
     * @return int
68
     */
69
    public function getWidth(): int
70
    {
71
        return $this->width;
72
    }
73
74
    /**
75
     * Item length in mm in it's packed orientation.
76
     *
77
     * @return int
78
     */
79
    public function getLength(): int
80
    {
81
        return $this->length;
82
    }
83
84
    /**
85
     * Item depth in mm in it's packed orientation.
86
     *
87
     * @return int
88
     */
89
    public function getDepth(): int
90
    {
91
        return $this->depth;
92
    }
93
94
    /**
95
     * Is this orientation stable (low centre of gravity)
96
     * N.B. Assumes equal weight distribution.
97
     *
98
     * @return bool
99
     */
100
    public function isStable(): bool
101
    {
102
        return $this->getDepth() <= min($this->getLength(), $this->getWidth());
103
    }
104
}
105