Completed
Pull Request — master (#54)
by Marko
02:34
created

ScaleComponent::setValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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         ScaleComponent.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\Scale;
25
26
use \AframeVR\Interfaces\Core\Components\ScaleCMPTIF;
27
use \AframeVR\Core\Helpers\ComponentAbstract;
28
use \AframeVR\Core\Helpers\ComponentHelper;
29
30 View Code Duplication
class ScaleComponent extends ComponentAbstract implements ScaleCMPTIF
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 Scale Component
36
     *
37
     * The scale component defines a shrinking, stretching, or skewing transformation of an entity.
38
     * It takes three scaling factors for the X, Y, and Z axes.
39
     *
40
     * Scale compnent dom attribute is scale
41
     *
42
     * {@inheritdoc}
43
     *
44
     * @return bool
45
     */
46 76
    public function initializeComponent(): bool
47
    {
48 76
        $this->setDomAttribute('scale');
49 76
        return true;
50
    }
51
52
    /**
53
     * Scaling factor in the X direction.
54
     *
55
     * {@inheritdoc}
56
     *
57
     * @param double $scale_x            
58
     * @return ScaleCMPTIF
59
     */
60 10
    public function scaleX(float $scale_x): ScaleCMPTIF
61
    {
62 10
        $this->setValues();
63 10
        $this->dom_attributes['x'] = $scale_x;
64 10
        return $this;
65
    }
66
67
    /**
68
     * Scaling factor in the Y direction..
69
     *
70
     * {@inheritdoc}
71
     *
72
     * @param double $scale_y            
73
     * @return ScaleCMPTIF
74
     */
75 9
    public function scaleY(float $scale_y): ScaleCMPTIF
76
    {
77 9
        $this->setValues();
78 9
        $this->dom_attributes['y'] = $scale_y;
79 9
        return $this;
80
    }
81
82
    /**
83
     * Scaling factor in the Z direction.
84
     *
85
     * {@inheritdoc}
86
     *
87
     * @param double $scale_z            
88
     * @return ScaleCMPTIF
89
     */
90 9
    public function scaleZ(float $scale_z): ScaleCMPTIF
91
    {
92 9
        $this->setValues();
93 9
        $this->dom_attributes['z'] = $scale_z;
94 9
        return $this;
95
    }
96
97
    /**
98
     * Get scale
99
     *
100
     * {@inheritdoc}
101
     *
102
     * @return string
103
     */
104 1
    public function getScale(): string
105
    {
106 1
        return $this->getDomAttributeString();
107
    }
108
109
    /**
110
     * Return DOM attribute contents
111
     *
112
     * Scale Components dom atribute contains coordinates
113
     * Ex: scale="1 1 1"
114
     *
115
     * {@inheritdoc}
116
     *
117
     * @return string
118
     */
119 4
    public function getDomAttributeString(): string
120
    {
121 4
        $attrs = $this->getDOMAttributesArray();
122 4
        return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']);
123
    }
124
125
    /**
126
     * When any scale component methods are called then init others
127
     *
128
     * @return void
129
     */
130 10
    private function setValues()
131
    {
132 10
        $this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0;
133 10
        $this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0;
134 10
        $this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0;
135 10
    }
136
}
137