Passed
Push — 1.x-dev ( 8f914b...081a6e )
by Doug
04:31
created

PackedItem   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 3 Features 0
Metric Value
eloc 32
c 3
b 3
f 0
dl 0
loc 150
ccs 36
cts 36
cp 1
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getZ() 0 3 1
A getY() 0 3 1
A getX() 0 3 1
A getItem() 0 3 1
A getLength() 0 3 1
A getWidth() 0 3 1
A getDepth() 0 3 1
A __construct() 0 9 1
A fromOrientatedItem() 0 10 1
A toOrientatedItem() 0 3 1
A getVolume() 0 3 1
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem).
4
 *
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker;
9
10
/**
11
 * A packed item.
12
 *
13
 * @author Doug Wright
14
 */
15
class PackedItem
16
{
17
    /**
18
     * @var int
19
     */
20
    protected $x;
21
22
    /**
23
     * @var int
24
     */
25
    protected $y;
26
27
    /**
28
     * @var int
29
     */
30
    protected $z;
31
32
    /**
33
     * @var Item
34
     */
35
    protected $item;
36
37
    /**
38
     * @var int
39
     */
40
    protected $width;
41
42
    /**
43
     * @var int
44
     */
45
    protected $length;
46
47
    /**
48
     * @var int
49
     */
50
    protected $depth;
51
52
    /**
53
     * PackedItem constructor.
54
     *
55
     * @param Item $item
56
     * @param int  $x
57
     * @param int  $y
58
     * @param int  $z
59
     * @param int  $width
60
     * @param int  $length
61
     * @param int  $depth
62
     */
63 20
    public function __construct(Item $item, $x, $y, $z, $width, $length, $depth)
64
    {
65 20
        $this->item = $item;
66 20
        $this->x = $x;
67 20
        $this->y = $y;
68 20
        $this->z = $z;
69 20
        $this->width = $width;
70 20
        $this->length = $length;
71 20
        $this->depth = $depth;
72 20
    }
73
74
    /**
75
     * @return int
76
     */
77 19
    public function getX()
78
    {
79 19
        return $this->x;
80
    }
81
82
    /**
83
     * @return int
84
     */
85 19
    public function getY()
86
    {
87 19
        return $this->y;
88
    }
89
90
    /**
91
     * @return int
92
     */
93 19
    public function getZ()
94
    {
95 19
        return $this->z;
96
    }
97
98
    /**
99
     * @return Item
100
     */
101 19
    public function getItem()
102
    {
103 19
        return $this->item;
104
    }
105
106
    /**
107
     * @return int
108
     */
109 19
    public function getWidth()
110
    {
111 19
        return $this->width;
112
    }
113
114
    /**
115
     * @return int
116
     */
117 19
    public function getLength()
118
    {
119 19
        return $this->length;
120
    }
121
122
    /**
123
     * @return int
124
     */
125 19
    public function getDepth()
126
    {
127 19
        return $this->depth;
128
    }
129
130
    /**
131
     * @return int
132
     */
133 1
    public function getVolume()
134
    {
135 1
        return $this->width * $this->length * $this->depth;
136
    }
137
138
    /**
139
     * @param OrientatedItem $orientatedItem
140
     * @param int            $x
141
     * @param int            $y
142
     * @param int            $z
143
     *
144
     * @return PackedItem
145
     */
146 19
    public static function fromOrientatedItem(OrientatedItem $orientatedItem, $x, $y, $z)
147
    {
148 19
        return new static(
149 19
            $orientatedItem->getItem(),
150 19
            $x,
151 19
            $y,
152 19
            $z,
153 19
            $orientatedItem->getWidth(),
154 19
            $orientatedItem->getLength(),
155 19
            $orientatedItem->getDepth()
156
        );
157
    }
158
159
    /**
160
     * @return OrientatedItem
161
     */
162 18
    public function toOrientatedItem()
163
    {
164 18
        return new OrientatedItem($this->item, $this->width, $this->length, $this->depth);
165
    }
166
}
167