Code Duplication    Length = 101-102 lines in 3 locations

src/Components/Position.php 1 location

@@ 35-136 (lines=102) @@
32
 *
33
 * All entities inherently have the position component.
34
 */
35
class Position implements ComponentInterface
36
{
37
38
    /**
39
     * Negative X axis extends left.
40
     *
41
     * Positive X Axis extends right.
42
     *
43
     * @var integer|double $x
44
     */
45
    protected $x;
46
47
    /**
48
     * Negative Y axis extends up.
49
     * Positive Y Axis extends down.
50
     *
51
     * @var integer|double $y
52
     */
53
    protected $y;
54
55
    /**
56
     * Negative Z axis extends in.
57
     * Positive Z Axis extends out.
58
     *
59
     * @var integer|double $z
60
     */
61
    protected $z;
62
63
    /**
64
     * Constructor
65
     *
66
     * @param integer|double $x            
67
     * @param integer|double $y            
68
     * @param integer|double $z            
69
     */
70
    public function __construct(float $x = 0, float $y = 0, float $z = 0)
71
    {
72
        $this->update($x, $y, $z);
73
    }
74
75
    /**
76
     * Get Component scripts
77
     *
78
     * {@inheritdoc}
79
     *
80
     * @return array
81
     */
82
    public function getScripts(): array
83
    {
84
        return array();
85
    }
86
87
    /**
88
     * Does component have DOM Atributes
89
     *
90
     * {@inheritdoc}
91
     *
92
     * @return bool
93
     */
94
    public function hasDOMAttributes(): bool
95
    {
96
        return ! empty(get_object_vars($this));
97
    }
98
99
    /**
100
     * Remove default DOMElement Attributes which are not required
101
     *
102
     * @return void
103
     */
104
    public function removeDefaultDOMAttributes()
105
    {
106
        if (empty($this->x) && empty($this->y) && empty($this->z)) {
107
            unset($this->x);
108
            unset($this->y);
109
            unset($this->z);
110
        }
111
    }
112
113
    /**
114
     * Get DOMAttr for the entity
115
     *
116
     * @return DOMAttr
117
     */
118
    public function getDOMAttributes(): DOMAttr
119
    {
120
        return new \DOMAttr('position', sprintf('%s %s %s', $this->x, $this->y, $this->z));
121
    }
122
123
    /**
124
     * Update coordinates
125
     *
126
     * @param integer|double $x            
127
     * @param integer|double $y            
128
     * @param integer|double $z            
129
     */
130
    public function update(float $x = 0, float $y = 0, float $z = 0)
131
    {
132
        $this->x = $x ?? 0;
133
        $this->y = $y ?? 0;
134
        $this->z = $z ?? 0;
135
    }
136
}

src/Components/Rotation.php 1 location

@@ 36-136 (lines=101) @@
33
 *
34
 * All entities inherently have the rotation component.
35
 */
36
class Rotation implements ComponentInterface
37
{
38
39
    /**
40
     * Roll, rotation about the X-axis.
41
     *
42
     * @var integer|double $x
43
     */
44
    protected $x;
45
46
    /**
47
     * Pitch, rotation about the Y-axis.
48
     *
49
     * @var integer|double $y
50
     */
51
    protected $y;
52
53
    /**
54
     * Yaw, rotation about the Z-axis.
55
     *
56
     * @var integer|double $z
57
     */
58
    protected $z;
59
60
    /**
61
     * Constructor
62
     *
63
     * @param integer|double $x            
64
     * @param integer|double $y            
65
     * @param integer|double $z            
66
     */
67
    public function __construct(float $x = 0, float $y = 0, float $z = 0)
68
    {
69
        $this->update($x, $y, $z);
70
    }
71
72
    /**
73
     * Get Component scripts
74
     *
75
     * {@inheritdoc}
76
     *
77
     * @return array
78
     */
79
    public function getScripts(): array
80
    {
81
        return array();
82
    }
83
84
    /**
85
     * Does component have DOM Atributes
86
     *
87
     * {@inheritdoc}
88
     *
89
     * @return bool
90
     */
91
    public function hasDOMAttributes(): bool
92
    {
93
        return ! empty(get_object_vars($this));
94
    }
95
96
    /**
97
     * Remove default DOMElement Attributes which are not required
98
     *
99
     * @return void
100
     */
101
    public function removeDefaultDOMAttributes()
102
    {
103
        if (empty($this->x) && empty($this->y) && empty($this->z)) {
104
            unset($this->x);
105
            unset($this->y);
106
            unset($this->z);
107
        }
108
    }
109
110
    /**
111
     * Get DOMAttr for the entity
112
     *
113
     * @return DOMAttr
114
     */
115
    public function getDOMAttributes(): DOMAttr
116
    {
117
        return new \DOMAttr('rotation', sprintf('%s %s %s', $this->x, $this->y, $this->z));
118
    }
119
120
    /**
121
     * Update rotation
122
     *
123
     * A-Frame uses a right-handed coordinate system. When aligning our right hand’s thumb with a positive axis,
124
     * our hand will curl in the positive direction of rotation.
125
     *
126
     * @param integer|double $x            
127
     * @param integer|double $y            
128
     * @param integer|double $z            
129
     */
130
    public function update(float $x = 0, float $y = 0, float $z = 0)
131
    {
132
        $this->x = $x ?? 0;
133
        $this->y = $y ?? 0;
134
        $this->z = $z ?? 0;
135
    }
136
}
137

src/Components/Scale.php 1 location

@@ 37-137 (lines=101) @@
34
 *
35
 * All entities inherently have the rotation component.
36
 */
37
class Scale implements ComponentInterface
38
{
39
40
    /**
41
     * Scaling factor in the X direction.
42
     *
43
     * @var integer|double $x
44
     */
45
    protected $x;
46
47
    /**
48
     * Scaling factor in the Y direction.
49
     *
50
     * @var integer|double $y
51
     */
52
    protected $y;
53
54
    /**
55
     * Scaling factor in the Z direction.
56
     *
57
     * @var integer|double $z
58
     */
59
    protected $z;
60
61
    /**
62
     * Constructor
63
     *
64
     * @param integer|double $x            
65
     * @param integer|double $y            
66
     * @param integer|double $z            
67
     */
68
    public function __construct(float $x = 0, float $y = 0, float $z = 0)
69
    {
70
        $this->update($x, $y, $z);
71
    }
72
73
    /**
74
     * Get Component scripts
75
     *
76
     * {@inheritdoc}
77
     *
78
     * @return array
79
     */
80
    public function getScripts(): array
81
    {
82
        return array();
83
    }
84
85
    /**
86
     * Does component have DOM Atributes
87
     *
88
     * {@inheritdoc}
89
     *
90
     * @return bool
91
     */
92
    public function hasDOMAttributes(): bool
93
    {
94
        return ! empty(get_object_vars($this));
95
    }
96
97
    /**
98
     * Remove default DOMElement Attributes which are not required
99
     *
100
     * @return void
101
     */
102
    public function removeDefaultDOMAttributes()
103
    {
104
        if (empty($this->x) && empty($this->y) && empty($this->z)) {
105
            unset($this->x);
106
            unset($this->y);
107
            unset($this->z);
108
        }
109
    }
110
111
    /**
112
     * Get DOMAttr for the entity
113
     *
114
     * @return DOMAttr
115
     */
116
    public function getDOMAttributes(): DOMAttr
117
    {
118
        return new \DOMAttr('scale', sprintf('%s %s %s', $this->x, $this->y, $this->z));
119
    }
120
121
    /**
122
     * Update scale
123
     *
124
     * If any of the scaling factors are set to 0, then A-Frame will
125
     * assign instead an extremely small value such that things don’t break.
126
     *
127
     * @param integer|double $x            
128
     * @param integer|double $y            
129
     * @param integer|double $z            
130
     */
131
    public function update(float $x = 0, float $y = 0, float $z = 00)
132
    {
133
        $this->x = $x ?? 0;
134
        $this->y = $y ?? 0;
135
        $this->z = $z ?? 0;
136
    }
137
}
138
139