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 |
||
12 | class Theme |
||
13 | { |
||
14 | protected $config; |
||
15 | |||
16 | protected $current; |
||
17 | |||
18 | protected $themes = []; |
||
19 | |||
20 | /** |
||
21 | * Theme constructor. |
||
22 | * |
||
23 | * @param array $config |
||
24 | */ |
||
25 | 11 | public function __construct($config = []) |
|
30 | |||
31 | /** |
||
32 | * Set Config. |
||
33 | * |
||
34 | * @param $config |
||
35 | */ |
||
36 | 1 | public function setConfig($config) |
|
41 | |||
42 | /** |
||
43 | * Initial Loading Themes. |
||
44 | * |
||
45 | * @param $path |
||
46 | */ |
||
47 | 11 | public function loadThemes($path) |
|
59 | |||
60 | /** |
||
61 | * Get all themes in theme catalog. |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | 2 | public function all() |
|
69 | |||
70 | /** |
||
71 | * Get Current Theme slug. |
||
72 | * |
||
73 | * @return mixed |
||
74 | */ |
||
75 | 6 | public function getCurrent() |
|
79 | |||
80 | /** |
||
81 | * Get Current Theme. |
||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | 1 | public function getCurrentTheme() |
|
89 | |||
90 | /** |
||
91 | * Set Current Theme. |
||
92 | * |
||
93 | * @param string $theme |
||
94 | */ |
||
95 | 11 | public function setCurrent($theme) |
|
99 | |||
100 | /** |
||
101 | * Active Theme. |
||
102 | * |
||
103 | * @param string $theme |
||
104 | */ |
||
105 | 1 | public function active($theme = '') |
|
109 | |||
110 | /** |
||
111 | * Get Theme Relative Asset. |
||
112 | * |
||
113 | * @param string $asset |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 1 | public function asset($asset) |
|
121 | |||
122 | /** |
||
123 | * Theme Is Current. |
||
124 | * |
||
125 | * @param string $theme |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 1 | public function isCurrent($theme) |
|
133 | |||
134 | /** |
||
135 | * Get Theme Absolute Path. |
||
136 | * |
||
137 | * @param string $theme |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 1 | View Code Duplication | public function absolutePath($theme = null) |
149 | |||
150 | /** |
||
151 | * Get Theme File Path. |
||
152 | * |
||
153 | * @param string $file |
||
154 | * @param string $theme |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 2 | View Code Duplication | public function path($file, $theme = null) |
166 | |||
167 | /** |
||
168 | * Parse Config to Object. |
||
169 | * |
||
170 | * @param $config |
||
171 | */ |
||
172 | 11 | protected function parseConfig($config) |
|
181 | } |
||
182 |
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.