Completed
Push — master ( 5f3088...bfb206 )
by Marko
02:40
created

Rotation::getScripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 21, 2016 - 12:10:50 PM
5
 * Contact      [email protected]
6
 * @copyright   2016 Marko Kungla - https://github.com/mkungla
7
 * @license     The MIT License (MIT)
8
 * 
9
 * @category       AframeVR
10
 * @package        aframe-php
11
 * 
12
 * Lang         PHP (php version >= 7)
13
 * Encoding     UTF-8
14
 * File         Rotation.php
15
 * Code format  PSR-2 and 12
16
 * @link        https://github.com/mkungla/aframe-php
17
 ^ @issues      https://github.com/mkungla/aframe-php/issues
18
 * ********************************************************************
19
 * Contributors:
20
 * @author Marko Kungla <[email protected]>
21
 * ********************************************************************
22
 * Comments:
23
 * @formatter:on */
24
namespace AframeVR\Components;
25
26
use \AframeVR\Interfaces\ComponentInterface;
27
use \DOMAttr;
28
29
/**
30
 * The rotation component defines the orientation of an entity.
31
 *
32
 * It takes the roll (x), pitch (y), and yaw (z) as three space-delimited numbers indicating degrees of rotation.
33
 *
34
 * All entities inherently have the rotation component.
35
 */
36 View Code Duplication
class Rotation implements ComponentInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 51
    public function __construct(float $x = 0, float $y = 0, float $z = 0)
68
    {
69 51
        $this->update($x, $y, $z);
70 51
    }
71
72
    /**
73
     * Get Component scripts
74
     *
75
     * {@inheritdoc}
76
     *
77
     * @return array
78
     */
79 1
    public function getScripts(): array
80
    {
81 1
        return array();
82
    }
83
84
    /**
85
     * Does component have DOM Atributes
86
     *
87
     * {@inheritdoc}
88
     *
89
     * @return bool
90
     */
91 5
    public function hasDOMAttributes(): bool
92
    {
93 5
        return ! empty(get_object_vars($this));
94
    }
95
96
    /**
97
     * Remove default DOMElement Attributes which are not required
98
     *
99
     * @return void
100
     */
101 5
    public function removeDefaultDOMAttributes()
102
    {
103 5
        if (empty($this->x) && empty($this->y) && empty($this->z)) {
104 4
            unset($this->x);
105 4
            unset($this->y);
106 4
            unset($this->z);
107
        }
108 5
    }
109
110
    /**
111
     * Get DOMAttr for the entity
112
     *
113
     * @return DOMAttr
114
     */
115 1
    public function getDOMAttributes(): DOMAttr
116
    {
117 1
        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 51
    public function update(float $x = 0, float $y = 0, float $z = 0)
131
    {
132 51
        $this->x = $x ?? 0;
133 51
        $this->y = $y ?? 0;
134 51
        $this->z = $z ?? 0;
135 51
    }
136
}
137