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 TDMCreateMoreFiles extends TDMCreateFile |
||
| 29 | { |
||
| 30 | // |
||
| 31 | private $folder; |
||
| 32 | // |
||
| 33 | private $extension; |
||
| 34 | /* |
||
| 35 | * @public function constructor |
||
| 36 | * @param null |
||
| 37 | */ |
||
| 38 | /** |
||
| 39 | * |
||
| 40 | */ |
||
| 41 | public function __construct() |
||
| 45 | |||
| 46 | /* |
||
| 47 | * @static function &getInstance |
||
| 48 | * @param null |
||
| 49 | */ |
||
| 50 | /** |
||
| 51 | * @return TDMCreateMoreFiles |
||
| 52 | */ |
||
| 53 | public static function &getInstance() |
||
| 62 | |||
| 63 | /* |
||
| 64 | * @public function write |
||
| 65 | * @param string $module |
||
| 66 | * @param string $filename |
||
| 67 | */ |
||
| 68 | /** |
||
| 69 | * @param $module |
||
| 70 | * @param $filename |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function write($module, $filename, $folder, $extension) |
|
| 85 | |||
| 86 | /* |
||
| 87 | * @private function getMoreFilesPhp |
||
| 88 | * @param $header |
||
| 89 | */ |
||
| 90 | /** |
||
| 91 | * @param $header |
||
| 92 | * |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | private function getMoreFilesPhp($header) |
||
| 106 | |||
| 107 | /* |
||
| 108 | * @private function getMoreFilesTpl |
||
| 109 | * @param $header |
||
| 110 | */ |
||
| 111 | /** |
||
| 112 | * @param $header |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | private function getMoreFilesTpl() |
||
| 126 | |||
| 127 | /* |
||
| 128 | * @private function getMoreFilesHtml |
||
| 129 | * @param $header |
||
| 130 | */ |
||
| 131 | /** |
||
| 132 | * @param $header |
||
| 133 | * |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | private function getMoreFilesHtml() |
||
| 146 | |||
| 147 | /* |
||
| 148 | * @private function getMoreFilesText |
||
| 149 | * @param null |
||
| 150 | */ |
||
| 151 | /** |
||
| 152 | * @param null |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | private function getMoreFilesText() |
||
| 164 | |||
| 165 | /* |
||
| 166 | * @private function getMoreFilesSql |
||
| 167 | * @param null |
||
| 168 | */ |
||
| 169 | /** |
||
| 170 | * @param null |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | private function getMoreFilesSql() |
||
| 182 | |||
| 183 | /* |
||
| 184 | * @private function getMoreFilesCss |
||
| 185 | * @param $header |
||
| 186 | */ |
||
| 187 | /** |
||
| 188 | * @param $header |
||
| 189 | * |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | private function getMoreFilesCss($header) |
||
| 201 | |||
| 202 | /* |
||
| 203 | * @private function getMoreFilesDefault |
||
| 204 | * @param null |
||
| 205 | */ |
||
| 206 | /** |
||
| 207 | * @param null |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | private function getMoreFilesDefault() |
||
| 219 | |||
| 220 | /* |
||
| 221 | * @public function render |
||
| 222 | * @param string $filename |
||
| 223 | */ |
||
| 224 | /** |
||
| 225 | * @param $filename |
||
| 226 | * |
||
| 227 | * @return bool|string |
||
| 228 | */ |
||
| 229 | public function render() |
||
| 263 | } |
||
| 264 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.