Component::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 8
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
    public function __construct(array $sectionsCoordinates)
24
    {
25
        $this->top = Side::fromRawPoints($sectionsCoordinates[Side::TOP]);
26
        $this->bottom = Side::fromRawPoints($sectionsCoordinates[Side::BOTTOM]);
27
        $this->front = Side::fromRawPoints($sectionsCoordinates[Side::FRONT]);
28
        $this->back = Side::fromRawPoints($sectionsCoordinates[Side::BACK]);
29
        $this->right = Side::fromRawPoints($sectionsCoordinates[Side::RIGHT]);
30
        $this->left = Side::fromRawPoints($sectionsCoordinates[Side::LEFT]);
31
    }
32
33
    public function getTop(): Side
34
    {
35
        return $this->top;
36
    }
37
38
    public function getBottom(): Side
39
    {
40
        return $this->bottom;
41
    }
42
43
    public function getFront(): Side
44
    {
45
        return $this->front;
46
    }
47
48
    public function getBack(): Side
49
    {
50
        return $this->back;
51
    }
52
53
    public function getRight(): Side
54
    {
55
        return $this->right;
56
    }
57
58
    public function getLeft(): Side
59
    {
60
        return $this->left;
61
    }
62
63
    /**
64
     * @throws \Exception
65
     */
66
    public function getSideByIdentifier(string $side): Side
67
    {
68
        return match ($side) {
69
            Side::TOP => $this->getTop(),
70
            Side::BOTTOM => $this->getBottom(),
71
            Side::FRONT => $this->getFront(),
72
            Side::BACK => $this->getBack(),
73
            Side::RIGHT => $this->getRight(),
74
            Side::LEFT => $this->getLeft(),
75
            default => throw new \Exception("Invalid Side {$side}")
76
        };
77
    }
78
79
    public static function getHead(): self
80
    {
81
        return new self(Coordinates::HEAD);
82
    }
83
84
    public static function getHeadLayer(): self
85
    {
86
        return new self(Coordinates::HEAD_LAYER);
87
    }
88
89
    public static function getTorso(): self
90
    {
91
        return new self(Coordinates::TORSO);
92
    }
93
94
    public static function getTorsoLayer(): self
95
    {
96
        return new self(Coordinates::TORSO_LAYER);
97
    }
98
99
    public static function getRightArm(): self
100
    {
101
        return new self(Coordinates::RIGHT_ARM);
102
    }
103
104
    public static function getRightArmLayer(): self
105
    {
106
        return new self(Coordinates::RIGHT_ARM_LAYER);
107
    }
108
109
    public static function getLeftArm(): self
110
    {
111
        return new self(Coordinates::LEFT_ARM);
112
    }
113
114
    public static function getLeftArmLayer(): self
115
    {
116
        return new self(Coordinates::LEFT_ARM_LAYER);
117
    }
118
119
    public static function getRightLeg(): self
120
    {
121
        return new self(Coordinates::RIGHT_LEG);
122
    }
123
124
    public static function getRightLegLayer(): self
125
    {
126
        return new self(Coordinates::RIGHT_LEG_LAYER);
127
    }
128
129
    public static function getLeftLeg(): self
130
    {
131
        return new self(Coordinates::LEFT_LEG);
132
    }
133
134
    public static function getLeftLegLayer(): self
135
    {
136
        return new self(Coordinates::LEFT_LEG_LAYER);
137
    }
138
}
139