Completed
Push — master ( 697c38...fae26d )
by Marko
9s
created

PositionComponent::positionZ()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 25, 2016 - 7:51:42 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         PositionComponent.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\Core\Components\Position;
25
26
use \AframeVR\Interfaces\Core\Components\PositionCMPTIF;
27
use \AframeVR\Core\Helpers\ComponentAbstract;
28
use \AframeVR\Core\Helpers\ComponentHelper;
29
30 View Code Duplication
class PositionComponent extends ComponentAbstract implements PositionCMPTIF
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...
31
{
32
    use ComponentHelper;
33
34
    /**
35
     * Initialize Position Component
36
     *
37
     * The position component defines where an entity is placed in the scene's world space.
38
     * It takes a coordinate value as three space-delimited numbers.
39
     *
40
     * {@inheritdoc}
41
     *
42
     * @return bool
43
     *
44
     */
45 76
    public function initializeComponent(): bool
46
    {
47 76
        $this->setDomAttribute('position');
48
        
49 76
        return true;
50
    }
51
52
    /**
53
     * Return DOM attribute contents
54
     *
55
     * Position Components dom atribute contains coordinates to point in world
56
     * Ex: position="1 1 1"
57
     *
58
     * @return string
59
     */
60 6
    public function getDomAttributeString(): string
61
    {
62 6
        $attrs = $this->getDOMAttributesArray();
63
        
64 6
        return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']);
65
    }
66
67
    /**
68
     * Get current position coordinates
69
     *
70
     * {@inheritdoc}
71
     *
72
     * @return string
73
     */
74 1
    public function getPosition(): string
75
    {
76 1
        return $this->getDomAttributeString();
77
    }
78
79
    /**
80
     * Negative X axis extends left.
81
     * Positive X Axis extends right.
82
     *
83
     * @param float $x_axis            
84
     * @return PositionCMPTIF
85
     */
86 16
    public function positionX(float $x_axis): PositionCMPTIF
87
    {
88 16
        $this->init();
89 16
        $this->dom_attributes['x'] = $x_axis;
90 16
        return $this;
91
    }
92
93
    /**
94
     * Negative Y axis extends up.
95
     * Positive Y Axis extends down.
96
     *
97
     * @param float $y_axis            
98
     * @return PositionCMPTIF
99
     */
100 15
    public function positionY(float $y_axis): PositionCMPTIF
101
    {
102 15
        $this->init();
103 15
        $this->dom_attributes['y'] = $y_axis;
104 15
        return $this;
105
    }
106
107
    /**
108
     * Negative Z axis extends in.
109
     * Positive Z Axis extends out.
110
     *
111
     * @param float $z_axis            
112
     * @return PositionCMPTIF
113
     */
114 15
    public function positionZ(float $z_axis): PositionCMPTIF
115
    {
116 15
        $this->init();
117 15
        $this->dom_attributes['z'] = $z_axis;
118 15
        return $this;
119
    }
120
121
    /**
122
     * When any position component methods are called then init others
123
     *
124
     * @return void
125
     */
126 16
    private function init()
127
    {
128 16
        $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0;
129 16
        $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0;
130 16
        $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0;
131
    }
132
}