Passed
Push — master ( 83967e...069e77 )
by Mattia
04:42 queued 14s
created

Component::getSideByIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 10
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image\Components;
6
7
class Component
8
{
9
    public const HEAD = 'HEAD';
10
    public const TORSO = 'TORSO';
11
    public const RIGHT_ARM = 'RIGHT_ARM';
12
    public const LEFT_ARM = 'LEFT_ARM';
13
    public const RIGHT_LEG = 'RIGHT_LEG';
14
    public const LEFT_LEG = 'LEFT_LEG';
15
16
    protected Side $top;
17
    protected Side $bottom;
18
    protected Side $front;
19
    protected Side $back;
20
    protected Side $right;
21
    protected Side $left;
22
23
    /**
24
     * @param array $sectionsCoordinates
25
     */
26
    public function __construct(array $sectionsCoordinates)
27
    {
28
        $this->top = Side::fromRawPoints($sectionsCoordinates[Side::TOP]);
29
        $this->bottom = Side::fromRawPoints($sectionsCoordinates[Side::BOTTOM]);
30
        $this->front = Side::fromRawPoints($sectionsCoordinates[Side::FRONT]);
31
        $this->back = Side::fromRawPoints($sectionsCoordinates[Side::BACK]);
32
        $this->right = Side::fromRawPoints($sectionsCoordinates[Side::RIGHT]);
33
        $this->left = Side::fromRawPoints($sectionsCoordinates[Side::LEFT]);
34
    }
35
36
    /**
37
     * @return Side
38
     */
39
    public function getTop(): Side
40
    {
41
        return $this->top;
42
    }
43
44
    /**
45
     * @return Side
46
     */
47
    public function getBottom(): Side
48
    {
49
        return $this->bottom;
50
    }
51
52
    /**
53
     * @return Side
54
     */
55
    public function getFront(): Side
56
    {
57
        return $this->front;
58
    }
59
60
    /**
61
     * @return Side
62
     */
63
    public function getBack(): Side
64
    {
65
        return $this->back;
66
    }
67
68
    /**
69
     * @return Side
70
     */
71
    public function getRight(): Side
72
    {
73
        return $this->right;
74
    }
75
76
    /**
77
     * @return Side
78
     */
79
    public function getLeft(): Side
80
    {
81
        return $this->left;
82
    }
83
84
    /**
85
     * @param string $side
86
     *
87
     * @throws \Exception
88
     *
89
     * @return Side
90
     */
91
    public function getSideByIdentifier(string $side): Side
92
    {
93
        return match ($side) {
94
            Side::TOP => $this->getTop(),
95
            Side::BOTTOM => $this->getBottom(),
96
            Side::FRONT => $this->getFront(),
97
            Side::BACK => $this->getBack(),
98
            Side::RIGHT => $this->getRight(),
99
            Side::LEFT => $this->getLeft(),
100
            default => throw new \Exception("Invalid Side {$side}")
101
        };
102
    }
103
104
    /**
105
     * @return static
106
     */
107
    public static function getHead(): self
108
    {
109
        return new self(Coordinates::HEAD);
110
    }
111
112
    /**
113
     * @return static
114
     */
115
    public static function getHeadLayer(): self
116
    {
117
        return new self(Coordinates::HEAD_LAYER);
118
    }
119
120
    /**
121
     * @return static
122
     */
123
    public static function getTorso(): self
124
    {
125
        return new self(Coordinates::TORSO);
126
    }
127
128
    /**
129
     * @return static
130
     */
131
    public static function getTorsoLayer(): self
132
    {
133
        return new self(Coordinates::TORSO_LAYER);
134
    }
135
136
    /**
137
     * @return static
138
     */
139
    public static function getRightArm(): self
140
    {
141
        return new self(Coordinates::RIGHT_ARM);
142
    }
143
144
    /**
145
     * @return static
146
     */
147
    public static function getRightArmLayer(): self
148
    {
149
        return new self(Coordinates::RIGHT_ARM_LAYER);
150
    }
151
152
    /**
153
     * @return static
154
     */
155
    public static function getLeftArm(): self
156
    {
157
        return new self(Coordinates::LEFT_ARM);
158
    }
159
160
    /**
161
     * @return static
162
     */
163
    public static function getLeftArmLayer(): self
164
    {
165
        return new self(Coordinates::LEFT_ARM_LAYER);
166
    }
167
168
    /**
169
     * @return static
170
     */
171
    public static function getRightLeg(): self
172
    {
173
        return new self(Coordinates::RIGHT_LEG);
174
    }
175
176
    /**
177
     * @return static
178
     */
179
    public static function getRightLegLayer(): self
180
    {
181
        return new self(Coordinates::RIGHT_LEG_LAYER);
182
    }
183
184
    /**
185
     * @return static
186
     */
187
    public static function getLeftLeg(): self
188
    {
189
        return new self(Coordinates::LEFT_LEG);
190
    }
191
192
    /**
193
     * @return static
194
     */
195
    public static function getLeftLegLayer(): self
196
    {
197
        return new self(Coordinates::LEFT_LEG_LAYER);
198
    }
199
}
200