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 |
||
28 | class Standard implements ShaderInterface |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Base diffuse color. |
||
33 | */ |
||
34 | public $color = '#fff'; |
||
35 | |||
36 | /** |
||
37 | * Height of video (in pixels), if defining a video texture. |
||
38 | * |
||
39 | * @var unknown |
||
40 | */ |
||
41 | public $height = '360'; |
||
42 | |||
43 | /** |
||
44 | * Environment cubemap texture for reflections. |
||
45 | * |
||
46 | * Can be a selector to or a comma-separated list of URLs. |
||
47 | */ |
||
48 | public $envMap = false; |
||
49 | |||
50 | /** |
||
51 | * Whether or not material is affected by fog. |
||
52 | */ |
||
53 | public $fog = true; |
||
54 | |||
55 | /** |
||
56 | * How metallic the material is from 0 to 1. |
||
57 | */ |
||
58 | public $metalness = '0.5'; |
||
59 | |||
60 | /** |
||
61 | * How many times a texture (defined by src) repeats in the X and Y direction. |
||
62 | */ |
||
63 | public $repeat = '1 1'; |
||
64 | |||
65 | /** |
||
66 | * How rough the material is from 0 to 1. |
||
67 | * A rougher material will scatter |
||
68 | * reflected light in more directions than a smooth material. |
||
69 | */ |
||
70 | public $roughness = '0.5'; |
||
71 | |||
72 | /** |
||
73 | * Width of video (in pixels), if defining a video texture. |
||
74 | */ |
||
75 | public $width = '640'; |
||
76 | |||
77 | /** |
||
78 | * Image or video texture map. |
||
79 | * Can either be a selector to an <img> or <video>, or an inline URL. |
||
80 | */ |
||
81 | public $src = null; |
||
82 | |||
83 | View Code Duplication | public function removeDefaultDOMAttributes() |
|
91 | |||
92 | 3 | public function color(string $color = '#fff') |
|
93 | { |
||
94 | 3 | $this->color = $color; |
|
95 | 3 | } |
|
96 | |||
97 | public function height(string $height = '360') |
||
101 | |||
102 | public function envMap($envMap = false) |
||
106 | |||
107 | public function fog(bool $fog = true) |
||
111 | |||
112 | 3 | public function metalness(string $metalness = '0.5') |
|
113 | { |
||
114 | 3 | $this->metalness = $metalness; |
|
115 | 3 | } |
|
116 | |||
117 | public function repeat(string $repeat = '1 1') |
||
121 | |||
122 | 3 | public function roughness(string $roughness = '0.5') |
|
123 | { |
||
124 | 3 | $this->roughness = $roughness; |
|
125 | 3 | } |
|
126 | |||
127 | public function width($width = '640') |
||
131 | |||
132 | 3 | public function src(string $src = null) |
|
133 | { |
||
134 | 3 | $this->src = $src; |
|
136 | } |
||
137 |
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.