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

Scale   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 97
loc 97
ccs 8
cts 20
cp 0.4
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getScripts() 4 4 1
A hasDOMAttributes() 4 4 1
A removeDefaultDOMAttributes() 8 8 4
A getDOMAttributes() 4 4 1
A __construct() 4 4 1
A update() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 24, 2016 - 8:08:15 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         Scale.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 scale component defines a shrinking, stretching, or skewing transformation of an entity. 
30
 * It takes three scaling factors for the X, Y, and Z axes.
31
 *
32
 * All entities inherently have the rotation component.
33
 */
34 View Code Duplication
class Scale 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...
35
{
36
37
    /**
38
     * Negative X axis extends left.
39
     * Positive X Axis extends right.
40
     *
41
     * @var int $x
42
     */
43
    protected $x;
44
45
    /**
46
     * Negative Y axis extends up.
47
     * Positive Y Axis extends down.
48
     *
49
     * @var int $y
50
     */
51
    protected $y;
52
53
    /**
54
     * Negative Z axis extends in.
55
     * Positive Z Axis extends out.
56
     *
57
     * @var int $z
58
     */
59
    protected $z;
60
61
    /**
62
     * Set initial coordinates
63
     *
64
     * @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...
65
     */
66 1
    public function __construct($x = 0, $y = 0, $z = 0)
67
    {
68 1
        $this->update($x, $y, $z);
69 1
    }
70
71
    /**
72
     * Get Component scripts
73
     *
74
     * {@inheritdoc}
75
     *
76
     * @return array
77
     */
78
    public function getScripts(): array
79
    {
80
        return array();
81
    }
82
83
    /**
84
     * Does component have DOM Atributes
85
     *
86
     * {@inheritdoc}
87
     *
88
     * @return bool
89
     */
90
    public function hasDOMAttributes(): bool
91
    {
92
        return ! empty(get_object_vars($this));
93
    }
94
95
    /**
96
     * Remove default DOMElement Attributes which are not required
97
     *
98
     * @return void
99
     */
100
    public function removeDefaultDOMAttributes()
101
    {
102
        if ($this->x === 0 && $this->y === 0 && $this->z === 0) {
103
            unset($this->x);
104
            unset($this->y);
105
            unset($this->z);
106
        }
107
    }
108
109
    /**
110
     * Get DOMAttr for the entity
111
     *
112
     * @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...
113
     */
114
    public function getDOMAttributes(): \DOMAttr
115
    {
116
        return new \DOMAttr('scale', sprintf('%s %s %s', $this->x, $this->y, $this->z));
117
    }
118
119
    /**
120
     * Update coordinates
121
     *
122
     * @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...
123
     */
124 1
    public function update($x = 0, $y = 0, $z = 0)
125
    {
126 1
        $this->x = $x ?? 0;
127 1
        $this->y = $y ?? 0;
128 1
        $this->z = $z ?? 0;
129 1
    }
130
}
131
132