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 |
||
14 | class Router extends ExternalModule |
||
15 | { |
||
16 | /** Event showing that new gather resource file was created */ |
||
17 | const EVENT_CREATED = 'resource.created'; |
||
18 | /** Event showing that new gather resource file was created */ |
||
19 | const EVENT_START_GENERATE_RESOURCES = 'resource.start.generate.resources'; |
||
20 | |||
21 | /** @var string Marker for inserting generated JS link in template */ |
||
22 | public $jsMarker = '</body>'; |
||
23 | /** @var string Marker for inserting generated CSS link in template */ |
||
24 | public $cssMarker = '</head>'; |
||
25 | /** Cached resources path collection */ |
||
26 | public $cached = array(); |
||
27 | /** Collection of updated cached resources for notification of changes */ |
||
28 | public $updated = array(); |
||
29 | |||
30 | /** Identifier */ |
||
31 | protected $id = STATIC_RESOURCE_HANDLER; |
||
32 | |||
33 | /** Pointer to processing module */ |
||
34 | private $currentModule; |
||
35 | /** @var string Current processed resource */ |
||
36 | private $currentResource; |
||
37 | |||
38 | /** @see ModuleConnector::init() */ |
||
39 | public function init(array $params = array()) |
||
52 | |||
53 | public function gatherResources($path) |
||
|
|||
54 | { |
||
55 | // we need to read all resources at specified path |
||
56 | // we need to gather all CSS resources into one file |
||
57 | // we need to gather all LESS resources into one file |
||
58 | // we need to gather all SASS resources into one file |
||
59 | // we need to gather all COFFEE resources into one file |
||
60 | // we need to gather all JS resources into one file |
||
61 | // we need to be able to include all files separately into template in development |
||
62 | // we need handlers/events for each resource type gathered with less and our approach |
||
63 | // we have problems that our variables are splitted around modules to make this work |
||
64 | // we need to gather all files and then parse on come up with different solution |
||
65 | |||
66 | } |
||
67 | |||
68 | public function gatherResources($path) |
||
82 | |||
83 | public function generateResources($moduleList, $templatePath = 'default') |
||
153 | |||
154 | /** |
||
155 | * Core render handler for including CSS and JS resources to html |
||
156 | * |
||
157 | * @param string $view View content |
||
158 | * @param array $data View data |
||
159 | * @param null $module Module instance |
||
160 | * |
||
161 | * @return string Processed view content |
||
162 | */ |
||
163 | public function renderer(&$view, $data = array(), $module = null) |
||
184 | |||
185 | /** |
||
186 | * Inject CSS link into view. |
||
187 | * |
||
188 | * @param string $view View code |
||
189 | * @param string $path Resource path |
||
190 | * |
||
191 | * @return string Modified view |
||
192 | */ |
||
193 | protected function injectCSS($view, $path) |
||
202 | |||
203 | /** |
||
204 | * Inject JS link into view. |
||
205 | * |
||
206 | * @param string $view View code |
||
207 | * @param string $path Resource path |
||
208 | * |
||
209 | * @return string Modified view |
||
210 | */ |
||
211 | protected function injectJS($view, $path) |
||
220 | |||
221 | /** |
||
222 | * Callback for CSS url(...) rewriting. |
||
223 | * |
||
224 | * @param array $matches Regular expression matches collection |
||
225 | * |
||
226 | * @return string Rewritten url(..) with static resource handler url |
||
227 | * @throws ResourceNotFound |
||
228 | */ |
||
229 | public function replaceUrlCallback($matches) |
||
260 | } |
||
261 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.