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 |
||
| 9 | trait TFBCUtilities |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Support relative routes. |
||
| 13 | * |
||
| 14 | * @param string $route to load. |
||
| 15 | * @param string $routeIndex to use. |
||
| 16 | * |
||
| 17 | * @return string with active route. |
||
| 18 | */ |
||
| 19 | private function getActiveRoute($route, $routeIndex) |
||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Process content phase 2 and merge with new frontmatter into |
||
| 32 | * view structure. |
||
| 33 | * |
||
| 34 | * @param string &$views array to load view info into. |
||
| 35 | * @param string $route to load meta from. |
||
| 36 | * |
||
| 37 | * @return void |
||
| 38 | */ |
||
| 39 | private function processContentPhaseTwo(&$filtered) |
||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Load view details for additional route, merged with meta if any. |
||
| 69 | * |
||
| 70 | * @param string $route to load. |
||
| 71 | * |
||
| 72 | * @return array with view data details. |
||
| 73 | */ |
||
| 74 | private function loadAndParseRoute($route) |
||
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * Load view data for additional route, merged with meta if any. |
||
| 112 | * |
||
| 113 | * @param string $route to load. |
||
| 114 | * |
||
| 115 | * @return array with view data details. |
||
| 116 | */ |
||
| 117 | private function getDataForAdditionalRoute($route) |
||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | /** |
||
| 157 | * Parse text, find and update all a href to use baseurl. |
||
| 158 | * |
||
| 159 | * @param object &$filtered with text and excerpt to process. |
||
| 160 | * @param string $baseurl add as baseurl for all relative urls. |
||
| 161 | * |
||
| 162 | * @return void. |
||
| 163 | */ |
||
| 164 | View Code Duplication | private function addBaseurl2AnchorUrls(&$filtered, $baseurl) |
|
| 177 | |||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * Parse text, find and update all image source to use baseurl. |
||
| 182 | * |
||
| 183 | * @param object &$filtered with text and excerpt to process. |
||
| 184 | * @param string $baseurl add as baseurl for all relative urls. |
||
| 185 | * |
||
| 186 | * @return void. |
||
| 187 | */ |
||
| 188 | View Code Duplication | private function addBaseurl2ImageSource(&$filtered, $baseurl) |
|
| 201 | |||
| 202 | |||
| 203 | |||
| 204 | /** |
||
| 205 | * Get published date. |
||
| 206 | * |
||
| 207 | * @param array $frontmatter with details on dates. |
||
| 208 | * |
||
| 209 | * @return integer as time for publish time. |
||
| 210 | */ |
||
| 211 | private function getPublishTime($frontmatter) |
||
| 216 | } |
||
| 217 |