| Total Complexity | 87 |
| Total Lines | 700 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like TDMCreatePhpCode 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.
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 TDMCreatePhpCode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class TDMCreatePhpCode |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @static function getInstance |
||
| 32 | * @param null |
||
| 33 | * @return TDMCreatePhpCode |
||
| 34 | */ |
||
| 35 | public static function getInstance() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @public function getPhpCodeCommentLine |
||
| 47 | * @param $comment |
||
| 48 | * @param $var |
||
| 49 | * @param string $t |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | public function getPhpCodeCommentLine($comment = null, $var = null, $t = '') |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @public function getPhpCodeCommentMultiLine |
||
| 62 | * @param array $multiLine |
||
| 63 | * |
||
| 64 | * @param string $t |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | public function getPhpCodeCommentMultiLine($multiLine = [], $t = '') |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @public function getPhpCodeDefine |
||
| 85 | * @param $left |
||
| 86 | * @param $right |
||
| 87 | * |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public function getPhpCodeDefine($left, $right) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @public function getPhpCodeDefine |
||
| 97 | * @param $left |
||
| 98 | * @param $right |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | public function getPhpCodeDefined($left = 'XOOPS_ROOT_PATH', $right = 'Restricted access') |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @public function getPhpCodeGlobals |
||
| 109 | * @param $var |
||
| 110 | * @param $value |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | public function getPhpCodeGlobals($var, $value = '') |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @public function getPhpCodeGlobalsVariables |
||
| 127 | * @param $var |
||
| 128 | * @param $type |
||
| 129 | * |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | public function getPhpCodeGlobalsVariables($var = null, $type = 'REQUEST') |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @public function getPhpCodeRemoveCarriageReturn |
||
| 164 | * @param $string |
||
| 165 | * |
||
| 166 | * @param string $n |
||
| 167 | * @param string $t |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function getPhpCodeRemoveCarriageReturn($string, $n = "\n", $t = "\r") |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @public function getPhpCodeFileExists |
||
| 177 | * @param $filename |
||
| 178 | * |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function getPhpCodeFileExists($filename) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @public function getPhpCodeIncludeDir |
||
| 188 | * @param $directory |
||
| 189 | * @param $filename |
||
| 190 | * @param bool $once |
||
| 191 | * @param bool $isPath |
||
| 192 | * |
||
| 193 | * @param string $type |
||
| 194 | * @param string $t |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | public function getPhpCodeIncludeDir($directory = null, $filename = null, $once = false, $isPath = false, $type = 'include', $t = '') |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @public function getPhpCodeTernaryOperator |
||
| 221 | * @param $return |
||
| 222 | * @param $condition |
||
| 223 | * @param $one |
||
| 224 | * @param $two |
||
| 225 | * @param $t - Indentation |
||
| 226 | * |
||
| 227 | * @return string |
||
| 228 | */ |
||
| 229 | public function getPhpCodeTernaryOperator($return, $condition, $one, $two, $t = '') |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @public function getPhpCodeClass |
||
| 236 | * @param $name |
||
| 237 | * @param $content |
||
| 238 | * @param $extends |
||
| 239 | * @param $type |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getPhpCodeClass($name = null, $content = null, $extends = null, $type = null) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @public function getPhpCodeClass |
||
| 257 | * @param $type |
||
| 258 | * @param $name |
||
| 259 | * @param $assign |
||
| 260 | * @param $t - Indentation |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getPhpCodeVariableClass($type = 'private', $name = null, $assign = 'null', $t = '') |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @public function getPhpCodeFunction |
||
| 271 | * @param $name |
||
| 272 | * @param $params |
||
| 273 | * @param $content |
||
| 274 | * @param $method |
||
| 275 | * @param bool $isRef |
||
| 276 | * @param string $t - Indentation |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public function getPhpCodeFunction($name = null, $params = null, $content = null, $method = null, $isRef = false, $t = '') |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @public function getPhpCodeConditions |
||
| 293 | * @param string $condition |
||
| 294 | * @param string $operator |
||
| 295 | * @param string $type |
||
| 296 | * @param string $contentIf |
||
| 297 | * @param mixed $contentElse |
||
| 298 | * @param $t - Indentation |
||
| 299 | * |
||
| 300 | * @return string |
||
| 301 | */ |
||
| 302 | public function getPhpCodeConditions($condition = null, $operator = null, $type = null, $contentIf = null, $contentElse = false, $t = '') |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @public function getPhpCodeForeach |
||
| 321 | * @param string $array |
||
| 322 | * @param bool|string $arrayKey |
||
| 323 | * @param bool|string $key |
||
| 324 | * @param bool|string $value |
||
| 325 | * @param string $content |
||
| 326 | * |
||
| 327 | * @param string $t |
||
| 328 | * @return string |
||
| 329 | */ |
||
| 330 | public function getPhpCodeForeach($array, $arrayKey = false, $key = false, $value = false, $content = null, $t = '') |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @public function getPhpCodeFor |
||
| 351 | * @param $var |
||
| 352 | * @param $content |
||
| 353 | * @param $value |
||
| 354 | * @param $initVal |
||
| 355 | * @param $operator |
||
| 356 | * |
||
| 357 | * @param string $t |
||
| 358 | * @return string |
||
| 359 | */ |
||
| 360 | public function getPhpCodeFor($var = null, $content = null, $value = null, $initVal = null, $operator = null, $t = '') |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @public function getPhpCodeWhile |
||
| 371 | * @param $var |
||
| 372 | * @param $content |
||
| 373 | * @param $value |
||
| 374 | * @param $operator |
||
| 375 | * @param $t |
||
| 376 | * |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | public function getPhpCodeWhile($var = null, $content = null, $value = null, $operator = null, $t = '') |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @public function getPhpCodeSwitch |
||
| 390 | * |
||
| 391 | * @param $op |
||
| 392 | * @param $content |
||
| 393 | * @param $t |
||
| 394 | * |
||
| 395 | * @return string |
||
| 396 | */ |
||
| 397 | public function getPhpCodeSwitch($op = null, $content = null, $t = '') |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @public function getPhpCodeCaseSwitch |
||
| 409 | * |
||
| 410 | * @param $cases |
||
| 411 | * @param $defaultAfterCase |
||
| 412 | * @param $default |
||
| 413 | * @param $t |
||
| 414 | * |
||
| 415 | * @return string |
||
| 416 | */ |
||
| 417 | public function getPhpCodeCaseSwitch($cases = [], $defaultAfterCase = false, $default = false, $t = '') |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @public function getPhpCodeIsset |
||
| 448 | * @param $var |
||
| 449 | * @return string |
||
| 450 | */ |
||
| 451 | public function getPhpCodeIsset($var) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @public function getPhpCodeUnset |
||
| 458 | * @param string $var |
||
| 459 | * @param string $t |
||
| 460 | * @return string |
||
| 461 | */ |
||
| 462 | public function getPhpCodeUnset($var = '', $t = '') |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @public function getPhpCodeIsDir |
||
| 469 | * @param $var |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | public function getPhpCodeIsDir($var) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * @public function getPhpCodeImplode |
||
| 479 | * @param $left |
||
| 480 | * @param $right |
||
| 481 | * @return string |
||
| 482 | */ |
||
| 483 | public function getPhpCodeImplode($left, $right) |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @public function getPhpCodeExplode |
||
| 490 | * @param $left |
||
| 491 | * @param $right |
||
| 492 | * @return string |
||
| 493 | */ |
||
| 494 | public function getPhpCodeExplode($left, $right) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @public function getPhpCodeChmod |
||
| 501 | * @param $var |
||
| 502 | * @param string $perm |
||
| 503 | * @param string $t |
||
| 504 | * @return string |
||
| 505 | */ |
||
| 506 | public function getPhpCodeChmod($var, $perm = '0777', $t = '') |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @public function getPhpCodeMkdir |
||
| 513 | * @param $var |
||
| 514 | * @param string $perm |
||
| 515 | * @param string $t |
||
| 516 | * @return string |
||
| 517 | */ |
||
| 518 | public function getPhpCodeMkdir($var, $perm = '0777', $t = '') |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @public function getPhpCodeCopy |
||
| 525 | * @param $file |
||
| 526 | * @param string $newfile |
||
| 527 | * @param string $t |
||
| 528 | * @return string |
||
| 529 | */ |
||
| 530 | public function getPhpCodeCopy($file, $newfile = '', $t = '') |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @public function getPhpCodeArray |
||
| 537 | * @param $var |
||
| 538 | * @param $array |
||
| 539 | * @param bool $isParam |
||
| 540 | * |
||
| 541 | * @param string $t |
||
| 542 | * @return string |
||
| 543 | */ |
||
| 544 | public function getPhpCodeArray($var, $array = null, $isParam = false, $t = "\t\t") |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @public function getPhpCodeArrayType |
||
| 572 | * @param $var |
||
| 573 | * @param $type |
||
| 574 | * @param $left |
||
| 575 | * @param $right |
||
| 576 | * @param bool $isParam |
||
| 577 | * |
||
| 578 | * @param string $t |
||
| 579 | * @return string |
||
| 580 | */ |
||
| 581 | public function getPhpCodeArrayType($var, $type, $left, $right = null, $isParam = false, $t = "\t\t") |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @public function getPhpCodeSprintf |
||
| 595 | * @param $left |
||
| 596 | * @param $right |
||
| 597 | * @return string |
||
| 598 | */ |
||
| 599 | public function getPhpCodeSprintf($left, $right) |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @public function getPhpCodeEmpty |
||
| 606 | * @param $var |
||
| 607 | * @return string |
||
| 608 | */ |
||
| 609 | public function getPhpCodeEmpty($var) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @public function getPhpCodeHeader |
||
| 616 | * @param $var |
||
| 617 | * @return string |
||
| 618 | */ |
||
| 619 | public function getPhpCodeHeader($var) |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @public function getPhpCodeRawurlencode |
||
| 626 | * @param $var |
||
| 627 | * @return string |
||
| 628 | */ |
||
| 629 | public function getPhpCodeRawurlencode($var) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @public function getPhpCodePregFunzions |
||
| 636 | * @param $var |
||
| 637 | * @param $exp |
||
| 638 | * @param $str |
||
| 639 | * @param $val |
||
| 640 | * @param string $type |
||
| 641 | * @param bool $isParam |
||
| 642 | * |
||
| 643 | * @param string $t |
||
| 644 | * @return string |
||
| 645 | */ |
||
| 646 | public function getPhpCodePregFunzions($var, $exp, $str, $val, $type = 'match', $isParam = false, $t = "\t") |
||
| 657 | |||
| 658 | /** |
||
| 659 | * @public function getPhpCodeStrType |
||
| 660 | * @param $left |
||
| 661 | * @param $var |
||
| 662 | * @param $str |
||
| 663 | * @param $value |
||
| 664 | * @param string $type |
||
| 665 | * @param bool $isParam |
||
| 666 | * |
||
| 667 | * @param string $t |
||
| 668 | * @return string |
||
| 669 | */ |
||
| 670 | public function getPhpCodeStrType($left, $var, $str, $value, $type = 'replace', $isParam = false, $t = "\t") |
||
| 681 | |||
| 682 | /** |
||
| 683 | * @public function getPhpCodeStripTags |
||
| 684 | * @param $left |
||
| 685 | * @param $value |
||
| 686 | * @param bool $isParam |
||
| 687 | * |
||
| 688 | * @param string $t |
||
| 689 | * @return string |
||
| 690 | */ |
||
| 691 | public function getPhpCodeStripTags($left, $value, $isParam = false, $t = '') |
||
| 701 | |||
| 702 | /** |
||
| 703 | * @public function getPhpCodeHtmlentities |
||
| 704 | * @param $entitiesVar |
||
| 705 | * @param $entitiesQuote |
||
| 706 | * @return string |
||
| 707 | */ |
||
| 708 | public function getPhpCodeHtmlentities($entitiesVar, $entitiesQuote = false) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @public function getPhpCodeHtmlspecialchars |
||
| 718 | * @param $specialVar |
||
| 719 | * @param $specialQuote |
||
| 720 | * @return string |
||
| 721 | */ |
||
| 722 | public function getPhpCodeHtmlspecialchars($specialVar, $specialQuote = false) |
||
| 723 | { |
||
| 724 | $specialVar = (false !== $specialQuote) ? $specialVar . ', ' . $specialQuote : $specialVar; |
||
| 725 | $specialchars = "htmlspecialchars({$specialVar})"; |
||
| 726 | |||
| 727 | return $specialchars; |
||
| 728 | } |
||
| 730 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.