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 |
||
31 | final class Mixin extends AssetsAbstract implements MixinInterface |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * DOM tag name of asset item |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $element_tag = 'a-mixin'; |
||
40 | |||
41 | /** |
||
42 | * Array of mocked components |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $components = array(); |
||
47 | |||
48 | /** |
||
49 | * Load component for this entity |
||
50 | * |
||
51 | * @param string $component_name |
||
52 | * @throws \AframeVR\Core\Exceptions\BadComponentCallException |
||
53 | * @return object|null |
||
54 | */ |
||
55 | 2 | View Code Duplication | public function component(string $component_name) |
69 | |||
70 | /** |
||
71 | * Handle entity components |
||
72 | * |
||
73 | * Since we might need to customize these to have |
||
74 | * custom components loaded as $this->methosd aswell therefore |
||
75 | * we have these placeholder magic methods here |
||
76 | * |
||
77 | * @param string $component_name |
||
78 | * @param array $args |
||
79 | */ |
||
80 | 1 | View Code Duplication | public function __call(string $component_name, array $args) |
91 | |||
92 | /** |
||
93 | * material.color |
||
94 | * |
||
95 | * @param string $color |
||
96 | * @return EntityInterface |
||
97 | */ |
||
98 | 1 | public function color(string $color = 'gray') |
|
105 | |||
106 | /** |
||
107 | * material.metalness |
||
108 | * |
||
109 | * @param int|float $metalness |
||
110 | * @return EntityInterface |
||
111 | */ |
||
112 | 1 | public function metalness(float $metalness = 0) |
|
119 | |||
120 | /** |
||
121 | * material.roughness |
||
122 | * |
||
123 | * @param float $roughness |
||
124 | * @return EntityInterface |
||
125 | */ |
||
126 | 1 | public function roughness(float $roughness = 0.5) |
|
133 | |||
134 | /** |
||
135 | * material.src |
||
136 | * |
||
137 | * @param null|string $src |
||
138 | * @return EntityInterface |
||
139 | */ |
||
140 | 1 | public function src(string $src = null) |
|
147 | |||
148 | /** |
||
149 | * geometry.translate |
||
150 | * |
||
151 | * @param int|float $x |
||
152 | * @param int|float $y |
||
153 | * @param int|float $z |
||
154 | * @return EntityInterface |
||
155 | */ |
||
156 | 1 | public function translate(float $x = 0, float $y = 0, float $z = 0) |
|
161 | |||
162 | /** |
||
163 | * material.shader |
||
164 | * |
||
165 | * @param string $shader |
||
166 | * @return EntityInterface |
||
167 | */ |
||
168 | 1 | public function shader($shader = 'standard') |
|
173 | |||
174 | /** |
||
175 | * material.opacity |
||
176 | * |
||
177 | * @param float $opacity |
||
178 | * @return EntityInterface |
||
179 | */ |
||
180 | 1 | public function opacity(float $opacity = 1.0) |
|
185 | |||
186 | /** |
||
187 | * material.transparent |
||
188 | * |
||
189 | * @param bool $transparent |
||
190 | * @return EntityInterface |
||
191 | */ |
||
192 | 1 | public function transparent(bool $transparent = false) |
|
197 | } |
||
198 |
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.