Completed
Push — master ( 94f348...ce557b )
by Marko
02:44
created

Rotation::hasDOMAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
28
/**
29
 * The rotation component defines the orientation of an entity.
30
 *
31
 * It takes the roll (x), pitch (y), and yaw (z) as three space-delimited numbers indicating degrees of rotation.
32
 *
33
 * All entities inherently have the rotation component.
34
 */
35 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...
36
{
37
38
    /**
39
     * Negative X axis extends left.
40
     * Positive X Axis extends right.
41
     *
42
     * @var int $x
43
     */
44
    protected $x;
45
46
    /**
47
     * Negative Y axis extends up.
48
     * Positive Y Axis extends down.
49
     *
50
     * @var int $y
51
     */
52
    protected $y;
53
54
    /**
55
     * Negative Z axis extends in.
56
     * Positive Z Axis extends out.
57
     *
58
     * @var int $z
59
     */
60
    protected $z;
61
62
    /**
63
     * Set initial coordinates
64
     *
65
     * @param string $coordinates            
0 ignored issues
show
Bug introduced by
There is no parameter named $coordinates. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
66
     */
67 8
    public function __construct($x = 0, $y = 0, $z = 0)
68
    {
69 8
        $this->update($x, $y, $z);
70 8
    }
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 ($this->x === 0 && $this->y === 0 && $this->z === 0) {
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
0 ignored issues
show
Documentation introduced by
Should the return type not be \DOMAttr?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
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 coordinates
122
     *
123
     * @param string $coordinates            
0 ignored issues
show
Bug introduced by
There is no parameter named $coordinates. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
124
     */
125 8
    public function update($x = 0, $y = 0, $z = 0)
126
    {
127 8
        $this->x = $x ?? 0;
128 8
        $this->y = $y ?? 0;
129 8
        $this->z = $z ?? 0;
130 8
    }
131
}
132