Complex classes like TDMCreateHtmlSmartyCodes 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 TDMCreateHtmlSmartyCodes, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class TDMCreateHtmlSmartyCodes extends TDMCreateFile |
||
|
|
|||
| 29 | { |
||
| 30 | /* |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $htmlcode; |
||
| 34 | |||
| 35 | /* |
||
| 36 | * @public function constructor |
||
| 37 | * @param null |
||
| 38 | */ |
||
| 39 | /** |
||
| 40 | * |
||
| 41 | */ |
||
| 42 | public function __construct() |
||
| 46 | |||
| 47 | /* |
||
| 48 | * @static function &getInstance |
||
| 49 | * @param null |
||
| 50 | */ |
||
| 51 | /** |
||
| 52 | * @return TDMCreateHtmlSmartyCodes |
||
| 53 | */ |
||
| 54 | public static function &getInstance() |
||
| 63 | |||
| 64 | /* |
||
| 65 | * @public function getHtmlTag |
||
| 66 | * @param string $tag |
||
| 67 | * @param array $attributes |
||
| 68 | * @param string $content |
||
| 69 | * @param bool $closed |
||
| 70 | */ |
||
| 71 | /** |
||
| 72 | * @param $tag |
||
| 73 | * @param $attributes |
||
| 74 | * @param $content |
||
| 75 | * @param $closed |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function getHtmlTag($tag = '', $attributes = array(), $content = '', $closed = true) |
||
| 93 | |||
| 94 | /* |
||
| 95 | * @private function setAttributes |
||
| 96 | * @param array $attributes |
||
| 97 | */ |
||
| 98 | /** |
||
| 99 | * @param $attributes |
||
| 100 | * |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | private function getAttributes($attributes) |
||
| 114 | |||
| 115 | /* |
||
| 116 | * @public function getHtmlEmpty |
||
| 117 | * @param string $empty |
||
| 118 | */ |
||
| 119 | /** |
||
| 120 | * @param $empty |
||
| 121 | * |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | public function getHtmlEmpty($empty = '') |
||
| 128 | |||
| 129 | /* |
||
| 130 | * @public function getHtmlComment |
||
| 131 | * @param string $htmlComment |
||
| 132 | */ |
||
| 133 | /** |
||
| 134 | * @param $htmlComment |
||
| 135 | * |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | public function getHtmlComment($htmlComment = '') |
||
| 142 | |||
| 143 | /* |
||
| 144 | * @public function getHtmlBr |
||
| 145 | * @param string $brNumb |
||
| 146 | * @param string $class |
||
| 147 | */ |
||
| 148 | /** |
||
| 149 | * @param $brNumb |
||
| 150 | * @param $class |
||
| 151 | * |
||
| 152 | * @return string |
||
| 153 | */ |
||
| 154 | public function getHtmlBr($brNumb = 1, $htmlClass = '') |
||
| 164 | |||
| 165 | /* |
||
| 166 | * @public function getHtmlHNumb |
||
| 167 | * @param string $htmlHClass |
||
| 168 | * @param string $content |
||
| 169 | */ |
||
| 170 | /** |
||
| 171 | * @param $content |
||
| 172 | * @param $htmlHClass |
||
| 173 | * |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | public function getHtmlHNumb($content = '', $n = '1', $htmlHClass = '') |
||
| 183 | |||
| 184 | /* |
||
| 185 | * @public function getHtmlDiv |
||
| 186 | * @param string $class |
||
| 187 | * @param string $content |
||
| 188 | */ |
||
| 189 | /** |
||
| 190 | * @param $content |
||
| 191 | * @param $class |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | public function getHtmlDiv($content = '', $divClass = '') |
||
| 204 | |||
| 205 | /* |
||
| 206 | * @public function getHtmlPre |
||
| 207 | * @param string $class |
||
| 208 | * @param string $content |
||
| 209 | */ |
||
| 210 | /** |
||
| 211 | * @param $content |
||
| 212 | * @param $class |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getHtmlPre($content = '', $preClass = '') |
||
| 225 | |||
| 226 | /* |
||
| 227 | * @public function getHtmlSpan |
||
| 228 | * @param string $class |
||
| 229 | * @param string $content |
||
| 230 | */ |
||
| 231 | /** |
||
| 232 | * @param $content |
||
| 233 | * @param $class |
||
| 234 | * |
||
| 235 | * @return string |
||
| 236 | */ |
||
| 237 | public function getHtmlSpan($content = '', $spanClass = '') |
||
| 244 | |||
| 245 | /* |
||
| 246 | * @public function getHtmlParagraph |
||
| 247 | * @param string $class |
||
| 248 | * @param string $content |
||
| 249 | */ |
||
| 250 | /** |
||
| 251 | * @param $content |
||
| 252 | * @param $class |
||
| 253 | * |
||
| 254 | * @return string |
||
| 255 | */ |
||
| 256 | public function getHtmlParagraph($content = '', $pClass = '') |
||
| 265 | |||
| 266 | /* |
||
| 267 | * @public function getHtmlI |
||
| 268 | * @param string $class |
||
| 269 | * @param string $content |
||
| 270 | */ |
||
| 271 | /** |
||
| 272 | * @param $content |
||
| 273 | * @param $class |
||
| 274 | * |
||
| 275 | * @return string |
||
| 276 | */ |
||
| 277 | public function getHtmlI($content = '', $iClass = '') |
||
| 284 | |||
| 285 | /* |
||
| 286 | * @public function getHtmlUl |
||
| 287 | * @param string $class |
||
| 288 | * @param string $content |
||
| 289 | */ |
||
| 290 | /** |
||
| 291 | * @param $content |
||
| 292 | * @param $class |
||
| 293 | * |
||
| 294 | * @return string |
||
| 295 | */ |
||
| 296 | public function getHtmlUl($content = '', $ulClass = '') |
||
| 305 | |||
| 306 | /* |
||
| 307 | * @public function getHtmlOl |
||
| 308 | * @param string $class |
||
| 309 | * @param string $content |
||
| 310 | */ |
||
| 311 | /** |
||
| 312 | * @param $content |
||
| 313 | * @param $class |
||
| 314 | * |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function getHtmlOl($content = '', $olClass = '') |
||
| 326 | |||
| 327 | /* |
||
| 328 | * @public function getHtmlLi |
||
| 329 | * @param string $class |
||
| 330 | * @param string $content |
||
| 331 | */ |
||
| 332 | /** |
||
| 333 | * @param $content |
||
| 334 | * @param $class |
||
| 335 | * |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | public function getHtmlLi($content = '', $liClass = '') |
||
| 344 | |||
| 345 | /* |
||
| 346 | * @public function getHtmlStrong |
||
| 347 | * @param string $class |
||
| 348 | * @param string $content |
||
| 349 | */ |
||
| 350 | /** |
||
| 351 | * @param $content |
||
| 352 | * @param $class |
||
| 353 | * |
||
| 354 | * @return string |
||
| 355 | */ |
||
| 356 | public function getHtmlStrong($content = '', $strongClass = '') |
||
| 362 | |||
| 363 | /* |
||
| 364 | * @public function getHtmlAnchor |
||
| 365 | * @param string $class |
||
| 366 | * @param string $url |
||
| 367 | * @param string $target |
||
| 368 | * @param string $content |
||
| 369 | */ |
||
| 370 | /** |
||
| 371 | * @param $url |
||
| 372 | * @param $content |
||
| 373 | * @param $target |
||
| 374 | * @param $class |
||
| 375 | * |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | public function getHtmlAnchor($url = '#', $content = ' ', $title = '', $target = '', $aClass = '', $rel = '') |
||
| 386 | |||
| 387 | /* |
||
| 388 | * @public function getHtmlImage |
||
| 389 | * @param string $src |
||
| 390 | * @param string $alt |
||
| 391 | * @param string $class |
||
| 392 | */ |
||
| 393 | /** |
||
| 394 | * @param $src |
||
| 395 | * @param $alt |
||
| 396 | * @param $class |
||
| 397 | * |
||
| 398 | * @return string |
||
| 399 | */ |
||
| 400 | public function getHtmlImage($src = 'blank.gif', $alt = 'blank.gif', $imgClass = '') |
||
| 407 | |||
| 408 | /* |
||
| 409 | * @public function getHtmlTable |
||
| 410 | * @param string $class |
||
| 411 | * @param string $content |
||
| 412 | */ |
||
| 413 | /** |
||
| 414 | * @param $content |
||
| 415 | * @param $class |
||
| 416 | * |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | public function getHtmlTable($content = '', $tableClass = '') |
||
| 428 | |||
| 429 | /* |
||
| 430 | * @public function getHtmlTableThead |
||
| 431 | * @param string $class |
||
| 432 | * @param string $content |
||
| 433 | */ |
||
| 434 | /** |
||
| 435 | * @param $content |
||
| 436 | * @param $class |
||
| 437 | * |
||
| 438 | * @return string |
||
| 439 | */ |
||
| 440 | public function getHtmlTableThead($content = '', $theadClass = '') |
||
| 449 | |||
| 450 | /* |
||
| 451 | * @public function getHtmlTableTbody |
||
| 452 | * @param string $class |
||
| 453 | * @param string $content |
||
| 454 | */ |
||
| 455 | /** |
||
| 456 | * @param $content |
||
| 457 | * @param $class |
||
| 458 | * |
||
| 459 | * @return string |
||
| 460 | */ |
||
| 461 | public function getHtmlTableTbody($content = '', $tbodyClass = '') |
||
| 470 | |||
| 471 | /* |
||
| 472 | * @public function getHtmlTableTfoot |
||
| 473 | * @param string $class |
||
| 474 | * @param string $content |
||
| 475 | */ |
||
| 476 | /** |
||
| 477 | * @param $content |
||
| 478 | * @param $class |
||
| 479 | * |
||
| 480 | * @return string |
||
| 481 | */ |
||
| 482 | public function getHtmlTableTfoot($content = '', $tfootClass = '') |
||
| 491 | |||
| 492 | /* |
||
| 493 | * @public function getHtmlTableRow |
||
| 494 | * @param string $class |
||
| 495 | * @param string $content |
||
| 496 | */ |
||
| 497 | /** |
||
| 498 | * @param $content |
||
| 499 | * @param $class |
||
| 500 | * |
||
| 501 | * @return string |
||
| 502 | */ |
||
| 503 | public function getHtmlTableRow($content = '', $trClass = '') |
||
| 512 | |||
| 513 | /* |
||
| 514 | * @public function getHtmlTableHead |
||
| 515 | * @param string $class |
||
| 516 | * @param string $content |
||
| 517 | */ |
||
| 518 | /** |
||
| 519 | * @param $content |
||
| 520 | * @param $class |
||
| 521 | * @param $colspan |
||
| 522 | * |
||
| 523 | * @return string |
||
| 524 | */ |
||
| 525 | public function getHtmlTableHead($content = '', $thClass = '', $colspan = '') |
||
| 532 | |||
| 533 | /* |
||
| 534 | * @public function getHtmlTableData |
||
| 535 | * @param string $class |
||
| 536 | * @param string $content |
||
| 537 | */ |
||
| 538 | /** |
||
| 539 | * @param $content |
||
| 540 | * @param $class |
||
| 541 | * @param $colspan |
||
| 542 | * |
||
| 543 | * @return string |
||
| 544 | */ |
||
| 545 | public function getHtmlTableData($content = '', $tdClass = '', $colspan = '') |
||
| 552 | |||
| 553 | /* |
||
| 554 | * @public function getSmartyComment |
||
| 555 | * @param string $comment |
||
| 556 | */ |
||
| 557 | /** |
||
| 558 | * @param $comment |
||
| 559 | * |
||
| 560 | * @return string |
||
| 561 | */ |
||
| 562 | public function getSmartyComment($comment = '') |
||
| 566 | |||
| 567 | /* |
||
| 568 | * @public function getSmartyNoSimbol |
||
| 569 | * @param string $content |
||
| 570 | */ |
||
| 571 | /** |
||
| 572 | * @param $content |
||
| 573 | * |
||
| 574 | * @return string |
||
| 575 | */ |
||
| 576 | public function getSmartyNoSimbol($noSimbol = '') |
||
| 580 | |||
| 581 | /* |
||
| 582 | * @public function getSmartyConst |
||
| 583 | * @param string $language |
||
| 584 | * @param mixed $const |
||
| 585 | */ |
||
| 586 | /** |
||
| 587 | * @param $language |
||
| 588 | * @param $const |
||
| 589 | * |
||
| 590 | * @return string |
||
| 591 | */ |
||
| 592 | public function getSmartyConst($language, $const) |
||
| 596 | |||
| 597 | /* |
||
| 598 | * @public function getSmartySingleVar |
||
| 599 | * @param string $var |
||
| 600 | */ |
||
| 601 | /** |
||
| 602 | * @param string $var |
||
| 603 | * |
||
| 604 | * @return string |
||
| 605 | */ |
||
| 606 | public function getSmartySingleVar($var) |
||
| 610 | |||
| 611 | /* |
||
| 612 | * @public function getSmartyDoubleVar |
||
| 613 | * @param string $leftVar |
||
| 614 | * @param string $rightVar |
||
| 615 | */ |
||
| 616 | /** |
||
| 617 | * @param string $leftVar |
||
| 618 | * @param string $rightVar |
||
| 619 | * |
||
| 620 | * @return string |
||
| 621 | */ |
||
| 622 | public function getSmartyDoubleVar($leftVar, $rightVar) |
||
| 626 | |||
| 627 | /* |
||
| 628 | * @public function getSmartyIncludeFile |
||
| 629 | * @param string $name |
||
| 630 | */ |
||
| 631 | /** |
||
| 632 | * @param $moduleDirname |
||
| 633 | * @param $fileName |
||
| 634 | * @param $admin |
||
| 635 | * |
||
| 636 | * @return string |
||
| 637 | */ |
||
| 638 | public function getSmartyIncludeFile($moduleDirname, $fileName = 'header', $admin = false, $q = false) |
||
| 652 | |||
| 653 | /* |
||
| 654 | * @public function getSmartyIncludeFileListSection |
||
| 655 | * @param string $name |
||
| 656 | */ |
||
| 657 | /** |
||
| 658 | * @param $moduleDirname |
||
| 659 | * @param $fileName |
||
| 660 | * @param $tableFieldName |
||
| 661 | * |
||
| 662 | * @return string |
||
| 663 | */ |
||
| 664 | public function getSmartyIncludeFileListSection($moduleDirname, $fileName, $tableFieldName) |
||
| 668 | |||
| 669 | /* |
||
| 670 | * @public function getSmartyIncludeFileListForeach |
||
| 671 | * @param string $name |
||
| 672 | */ |
||
| 673 | /** |
||
| 674 | * @param $moduleDirname |
||
| 675 | * @param $fileName |
||
| 676 | * @param $tableFieldName |
||
| 677 | * |
||
| 678 | * @return string |
||
| 679 | */ |
||
| 680 | public function getSmartyIncludeFileListForeach($moduleDirname, $fileName, $tableFieldName) |
||
| 684 | |||
| 685 | /* |
||
| 686 | * @public function getSmartyConditions |
||
| 687 | * @param string $condition |
||
| 688 | * @param string $operator |
||
| 689 | * @param string $type |
||
| 690 | * @param string $contentIf |
||
| 691 | * @param mixed $contentElse |
||
| 692 | * @param bool $count |
||
| 693 | */ |
||
| 694 | /** |
||
| 695 | * @param string $condition |
||
| 696 | * @param string $operator |
||
| 697 | * @param string $type |
||
| 698 | * @param string $contentIf |
||
| 699 | * @param mixed $contentElse |
||
| 700 | * @param bool $count |
||
| 701 | * |
||
| 702 | * @return string |
||
| 703 | */ |
||
| 704 | public function getSmartyConditions($condition = '', $operator = '', $type = '', $contentIf = '', $contentElse = false, $count = false, $noSimbol = false) |
||
| 732 | |||
| 733 | /* |
||
| 734 | * @public function getSmartyForeach |
||
| 735 | * @param string $item |
||
| 736 | * @param string $from |
||
| 737 | * @param string $content |
||
| 738 | */ |
||
| 739 | /** |
||
| 740 | * @param string $item |
||
| 741 | * @param string $from |
||
| 742 | * @param string $content |
||
| 743 | * |
||
| 744 | * @return string |
||
| 745 | */ |
||
| 746 | public function getSmartyForeach($item = 'item', $from = 'from', $content = 'content', $name = '', $key = '') |
||
| 756 | |||
| 757 | /* |
||
| 758 | * @public function getSmartyForeachQuery |
||
| 759 | * @param string $item |
||
| 760 | * @param string $from |
||
| 761 | * @param string $content |
||
| 762 | */ |
||
| 763 | /** |
||
| 764 | * @param string $item |
||
| 765 | * @param string $from |
||
| 766 | * @param string $content |
||
| 767 | * |
||
| 768 | * @return string |
||
| 769 | */ |
||
| 770 | public function getSmartyForeachQuery($item = 'item', $from = 'from', $content = 'content', $loop = 'loop', $key = '') |
||
| 780 | |||
| 781 | /* |
||
| 782 | * @public function getSmartySection |
||
| 783 | * @param string $name |
||
| 784 | * @param string $loop |
||
| 785 | * @param string $content |
||
| 786 | */ |
||
| 787 | /** |
||
| 788 | * @param string $name |
||
| 789 | * @param string $loop |
||
| 790 | * @param string $content |
||
| 791 | * |
||
| 792 | * @return string |
||
| 793 | */ |
||
| 794 | public function getSmartySection($name = 'name', $loop = 'loop', $content = 'content', $start = 0, $step = 0) |
||
| 804 | } |
||
| 805 |
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.