Complex classes like TDMCreateSmartyCode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TDMCreateSmartyCode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class TDMCreateSmartyCode |
||
|
|
|||
| 29 | { |
||
| 30 | /* |
||
| 31 | * @public function constructor |
||
| 32 | * @param null |
||
| 33 | */ |
||
| 34 | /** |
||
| 35 | * |
||
| 36 | */ |
||
| 37 | public function __construct() |
||
| 40 | |||
| 41 | /* |
||
| 42 | * @static function &getInstance |
||
| 43 | * @param null |
||
| 44 | */ |
||
| 45 | /** |
||
| 46 | * @return TDMCreateSmartySmartyCodes |
||
| 47 | */ |
||
| 48 | public static function &getInstance() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @public function getSmartyTag |
||
| 60 | * |
||
| 61 | * @param $tag |
||
| 62 | * @param $attributes |
||
| 63 | * @param $content |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | public function getSmartyTag($tag = '', $attributes = array(), $content = '') |
||
| 77 | |||
| 78 | /* |
||
| 79 | * @private function setAttributes |
||
| 80 | * @param array $attributes |
||
| 81 | */ |
||
| 82 | /** |
||
| 83 | * @param $attributes |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | private function getAttributes($attributes) |
||
| 98 | |||
| 99 | /* |
||
| 100 | * @public function getSmartyEmpty |
||
| 101 | * @param string $empty |
||
| 102 | */ |
||
| 103 | /** |
||
| 104 | * @param $empty |
||
| 105 | * |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getSmartyEmpty($empty = '') |
||
| 112 | |||
| 113 | /* |
||
| 114 | * @public function getSmartyComment |
||
| 115 | * @param string $htmlComment |
||
| 116 | */ |
||
| 117 | /** |
||
| 118 | * @param $htmlComment |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function getSmartyComment($smartyComment = '') |
||
| 126 | |||
| 127 | /* |
||
| 128 | * @public function getSmartyNoSimbol |
||
| 129 | * @param string $content |
||
| 130 | */ |
||
| 131 | /** |
||
| 132 | * @param $content |
||
| 133 | * |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | public function getSmartyNoSimbol($noSimbol = '') |
||
| 140 | |||
| 141 | /* |
||
| 142 | * @public function getSmartyConst |
||
| 143 | * @param string $language |
||
| 144 | * @param mixed $const |
||
| 145 | */ |
||
| 146 | /** |
||
| 147 | * @param $language |
||
| 148 | * @param $const |
||
| 149 | * |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function getSmartyConst($language, $const) |
||
| 156 | |||
| 157 | /* |
||
| 158 | * @public function getSmartySingleVar |
||
| 159 | * @param string $var |
||
| 160 | */ |
||
| 161 | /** |
||
| 162 | * @param string $var |
||
| 163 | * |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function getSmartySingleVar($var) |
||
| 170 | |||
| 171 | /* |
||
| 172 | * @public function getSmartyDoubleVar |
||
| 173 | * @param string $leftVar |
||
| 174 | * @param string $rightVar |
||
| 175 | */ |
||
| 176 | /** |
||
| 177 | * @param string $leftVar |
||
| 178 | * @param string $rightVar |
||
| 179 | * |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getSmartyDoubleVar($leftVar, $rightVar) |
||
| 186 | |||
| 187 | /* |
||
| 188 | * @public function getSmartyIncludeFile |
||
| 189 | * @param string $name |
||
| 190 | */ |
||
| 191 | /** |
||
| 192 | * @param $moduleDirname |
||
| 193 | * @param $fileName |
||
| 194 | * @param $admin |
||
| 195 | * |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function getSmartyIncludeFile($moduleDirname, $fileName = 'header', $admin = false, $q = false) |
||
| 212 | |||
| 213 | /* |
||
| 214 | * @public function getSmartyIncludeFileListSection |
||
| 215 | * @param string $name |
||
| 216 | */ |
||
| 217 | /** |
||
| 218 | * @param $moduleDirname |
||
| 219 | * @param $fileName |
||
| 220 | * @param $tableFieldName |
||
| 221 | * |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function getSmartyIncludeFileListSection($moduleDirname, $fileName, $tableFieldName) |
||
| 228 | |||
| 229 | /* |
||
| 230 | * @public function getSmartyIncludeFileListForeach |
||
| 231 | * @param string $name |
||
| 232 | */ |
||
| 233 | /** |
||
| 234 | * @param $moduleDirname |
||
| 235 | * @param $fileName |
||
| 236 | * @param $tableFieldName |
||
| 237 | * |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function getSmartyIncludeFileListForeach($moduleDirname, $fileName, $tableFieldName) |
||
| 244 | |||
| 245 | /* |
||
| 246 | * @public function getSmartyConditions |
||
| 247 | * @param string $condition |
||
| 248 | * @param string $operator |
||
| 249 | * @param string $type |
||
| 250 | * @param string $contentIf |
||
| 251 | * @param mixed $contentElse |
||
| 252 | * @param bool $count |
||
| 253 | */ |
||
| 254 | /** |
||
| 255 | * @param string $condition |
||
| 256 | * @param string $operator |
||
| 257 | * @param string $type |
||
| 258 | * @param string $contentIf |
||
| 259 | * @param mixed $contentElse |
||
| 260 | * @param bool $count |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getSmartyConditions($condition = '', $operator = '', $type = '', $contentIf = '', $contentElse = false, $count = false, $noSimbol = false) |
||
| 292 | |||
| 293 | /* |
||
| 294 | * @public function getSmartyForeach |
||
| 295 | * @param string $item |
||
| 296 | * @param string $from |
||
| 297 | * @param string $content |
||
| 298 | */ |
||
| 299 | /** |
||
| 300 | * @param string $item |
||
| 301 | * @param string $from |
||
| 302 | * @param string $content |
||
| 303 | * |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | public function getSmartyForeach($item = 'item', $from = 'from', $content = 'content', $name = '', $key = '') |
||
| 316 | |||
| 317 | /* |
||
| 318 | * @public function getSmartyForeachQuery |
||
| 319 | * @param string $item |
||
| 320 | * @param string $from |
||
| 321 | * @param string $content |
||
| 322 | */ |
||
| 323 | /** |
||
| 324 | * @param string $item |
||
| 325 | * @param string $from |
||
| 326 | * @param string $content |
||
| 327 | * |
||
| 328 | * @return string |
||
| 329 | */ |
||
| 330 | public function getSmartyForeachQuery($item = 'item', $from = 'from', $content = 'content', $loop = 'loop', $key = '') |
||
| 340 | |||
| 341 | /* |
||
| 342 | * @public function getSmartySection |
||
| 343 | * @param string $name |
||
| 344 | * @param string $loop |
||
| 345 | * @param string $content |
||
| 346 | */ |
||
| 347 | /** |
||
| 348 | * @param string $name |
||
| 349 | * @param string $loop |
||
| 350 | * @param string $content |
||
| 351 | * |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | public function getSmartySection($name = 'name', $loop = 'loop', $content = 'content', $start = 0, $step = 0) |
||
| 364 | } |
||
| 365 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.