Passed
Push — 3.x ( fece24...05a09a )
by Doug
02:30
created

PackedItem::getZ()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
use JsonSerializable;
12
use ReturnTypeWillChange;
13
14
/**
15
 * A packed item.
16
 *
17
 * @author Doug Wright
18
 */
19
class PackedItem implements JsonSerializable
20
{
21
    /**
22
     * @var int
23
     */
24
    protected $x;
25
26
    /**
27
     * @var int
28
     */
29
    protected $y;
30
31
    /**
32
     * @var int
33
     */
34
    protected $z;
35
36
    /**
37
     * @var Item
38
     */
39
    protected $item;
40
41
    /**
42
     * @var int
43
     */
44
    protected $width;
45
46
    /**
47
     * @var int
48
     */
49
    protected $length;
50
51
    /**
52
     * @var int
53
     */
54
    protected $depth;
55
56
    /**
57
     * PackedItem constructor.
58
     */
59 83
    public function __construct(Item $item, int $x, int $y, int $z, int $width, int $length, int $depth)
60
    {
61 83
        $this->item = $item;
62 83
        $this->x = $x;
63 83
        $this->y = $y;
64 83
        $this->z = $z;
65 83
        $this->width = $width;
66 83
        $this->length = $length;
67 83
        $this->depth = $depth;
68 83
    }
69
70 81
    public function getX(): int
71
    {
72 81
        return $this->x;
73
    }
74
75 81
    public function getY(): int
76
    {
77 81
        return $this->y;
78
    }
79
80 81
    public function getZ(): int
81
    {
82 81
        return $this->z;
83
    }
84
85 81
    public function getItem(): Item
86
    {
87 81
        return $this->item;
88
    }
89
90 81
    public function getWidth(): int
91
    {
92 81
        return $this->width;
93
    }
94
95 81
    public function getLength(): int
96
    {
97 81
        return $this->length;
98
    }
99
100 81
    public function getDepth(): int
101
    {
102 81
        return $this->depth;
103
    }
104
105 81
    public function getVolume(): int
106
    {
107 81
        return $this->width * $this->length * $this->depth;
108
    }
109
110
    /**
111
     * @return PackedItem
112
     */
113 80
    public static function fromOrientatedItem(OrientatedItem $orientatedItem, int $x, int $y, int $z): self
114
    {
115 80
        return new static(
116 80
            $orientatedItem->getItem(),
117
            $x,
118
            $y,
119
            $z,
120 80
            $orientatedItem->getWidth(),
121 80
            $orientatedItem->getLength(),
122 80
            $orientatedItem->getDepth()
123
        );
124
    }
125
126
    /**
127
     * @deprecated
128
     */
129
    public function toOrientatedItem(): OrientatedItem
130
    {
131
        return new OrientatedItem($this->item, $this->width, $this->length, $this->depth);
132
    }
133
134 1
    #[ReturnTypeWillChange]
135
    public function jsonSerialize()/*: mixed*/
136
    {
137
        return [
138 1
            'x' => $this->x,
139 1
            'y' => $this->y,
140 1
            'z' => $this->z,
141 1
            'width' => $this->width,
142 1
            'length' => $this->length,
143 1
            'depth' => $this->depth,
144
            'item' => [
145 1
                'description' => $this->item->getDescription(),
146 1
                'width' => $this->item->getWidth(),
147 1
                'length' => $this->item->getLength(),
148 1
                'depth' => $this->item->getDepth(),
149 1
                'keepFlat' => $this->item->getKeepFlat(),
150
            ],
151
        ];
152
    }
153
}
154