| Total Complexity | 62 |
| Total Lines | 474 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CreateHtmlCode 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 CreateHtmlCode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class CreateHtmlCode |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @static function getInstance |
||
| 35 | * |
||
| 36 | * @param null |
||
| 37 | * |
||
| 38 | * @return CreateHtmlCode |
||
| 39 | */ |
||
| 40 | public static function getInstance() |
||
| 41 | { |
||
| 42 | static $instance = false; |
||
| 43 | if (!$instance) { |
||
| 44 | $instance = new self(); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $instance; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @public function getHtmlTag |
||
| 52 | * @param string $tag |
||
| 53 | * @param array $attributes |
||
| 54 | * @param string $content |
||
| 55 | * @param bool $noClosed |
||
| 56 | * @param string $t |
||
| 57 | * @param string $n |
||
| 58 | * @param bool $multiLine |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function getHtmlTag($tag = '', $attributes = [], $content = '', $noClosed = false, $t = '', $n = "\n", $multiLine = false) |
||
| 62 | { |
||
| 63 | if (empty($attributes)) { |
||
| 64 | $attributes = []; |
||
| 65 | } |
||
| 66 | $attr = $this->getAttributes($attributes); |
||
| 67 | if ('br' === $tag) { |
||
| 68 | $ret = "{$t}<{$tag}{$attr}>{$n}"; |
||
| 69 | } elseif ($noClosed) { |
||
| 70 | $ret = "{$t}<{$tag}{$attr} />{$n}"; |
||
| 71 | } elseif ($multiLine) { |
||
| 72 | $ret = "{$t}<{$tag}{$attr}>{$n}"; |
||
| 73 | $ret .= "{$content}"; |
||
| 74 | $ret .= "{$t}</{$tag}>{$n}"; |
||
| 75 | } else { |
||
| 76 | $ret = "{$t}<{$tag}{$attr}>{$content}</{$tag}>{$n}"; |
||
| 77 | } |
||
| 78 | |||
| 79 | return $ret; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @private function setAttributes |
||
| 84 | * @param array $attributes |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | private function getAttributes($attributes) |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @public function getHtmlEmpty |
||
| 101 | * @param string $empty |
||
| 102 | * @param string $t |
||
| 103 | * @param string $n |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | public function getHtmlEmpty($empty = '', $t = '', $n = '') |
||
| 107 | { |
||
| 108 | return "{$t}{$empty}{$n}"; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @public function getHtmlComment |
||
| 113 | * @param string $htmlComment |
||
| 114 | * @param string $n |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | public function getHtmlComment($htmlComment = '', $n = '') |
||
| 118 | { |
||
| 119 | return "<!-- {$htmlComment} -->{$n}"; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @public function getHtmlBr |
||
| 124 | * @param int $brNumb |
||
| 125 | * @param string $htmlClass |
||
| 126 | * @param string $t |
||
| 127 | * @param string $n |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getHtmlBr($brNumb = 1, $htmlClass = '', $t = '', $n = "\n") |
||
| 131 | { |
||
| 132 | $brClass = ('' != $htmlClass) ? " class='{$htmlClass}'" : ''; |
||
| 133 | $ret = ''; |
||
| 134 | for ($i = 0; $i < $brNumb; ++$i) { |
||
| 135 | $ret .= "{$t}<br{$brClass} />{$n}"; |
||
| 136 | } |
||
| 137 | |||
| 138 | return $ret; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @public function getHtmlHNumb |
||
| 143 | * @param string $content |
||
| 144 | * @param string $l |
||
| 145 | * @param string $htmlHClass |
||
| 146 | * @param string $t |
||
| 147 | * @param string $n |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | public function getHtmlHNumb($content = '', $l = '1', $htmlHClass = '', $t = '', $n = "\n") |
||
| 151 | { |
||
| 152 | $hClass = ('' != $htmlHClass) ? " class='{$htmlHClass}'" : ''; |
||
| 153 | $ret = "{$t}<h{$l}{$hClass}>{$content}</h{$l}>{$n}"; |
||
| 154 | |||
| 155 | return $ret; |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @public function getHtmlDiv |
||
| 160 | * @param string $content |
||
| 161 | * @param string $divClass |
||
| 162 | * @param string $t |
||
| 163 | * @param string $n |
||
| 164 | * @param bool $split |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | public function getHtmlDiv($content = '', $divClass = '', $t = '', $n = "\n", $split = true) |
||
| 168 | { |
||
| 169 | $rDivClass = ('' != $divClass) ? " class='{$divClass}'" : ''; |
||
| 170 | |||
| 171 | if ($split) { |
||
| 172 | $ret = "{$t}<div{$rDivClass}>{$n}"; |
||
| 173 | $ret .= "{$content}"; |
||
| 174 | $ret .= "{$t}</div>{$n}"; |
||
| 175 | } else { |
||
| 176 | $ret = "{$t}<div{$rDivClass}>{$content}</div>{$n}"; |
||
| 177 | } |
||
| 178 | |||
| 179 | return $ret; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @public function getHtmlPre |
||
| 184 | * @param string $content |
||
| 185 | * @param string $preClass |
||
| 186 | * @param string $t |
||
| 187 | * @param string $n |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | public function getHtmlPre($content = '', $preClass = '', $t = '', $n = "\n") |
||
| 191 | { |
||
| 192 | $rPreClass = ('' != $preClass) ? " class='{$preClass}'" : ''; |
||
| 193 | $ret = "{$t}<pre{$rPreClass}>{$n}"; |
||
| 194 | $ret .= "{$content}"; |
||
| 195 | $ret .= "{$t}</pre>{$n}"; |
||
| 196 | |||
| 197 | return $ret; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @public function getHtmlSpan |
||
| 202 | * @param string $content |
||
| 203 | * @param string $spanClass |
||
| 204 | * @param string $t |
||
| 205 | * @param string $n |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public function getHtmlSpan($content = '', $spanClass = '', $t = '', $n = "\n") |
||
| 209 | { |
||
| 210 | $rSpanClass = ('' != $spanClass) ? " class='{$spanClass}'" : ''; |
||
| 211 | $ret = "{$t}<span{$rSpanClass}>{$content}</span>{$n}"; |
||
| 212 | |||
| 213 | return $ret; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @public function getHtmlParagraph |
||
| 218 | * @param string $content |
||
| 219 | * @param string $pClass |
||
| 220 | * @param string $t |
||
| 221 | * @param string $n |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function getHtmlParagraph($content = '', $pClass = '', $t = '', $n = "\n") |
||
| 225 | { |
||
| 226 | $rPClass = ('' != $pClass) ? " class='{$pClass}'" : ''; |
||
| 227 | $ret = "{$t}<p{$rPClass}>{$n}"; |
||
| 228 | $ret .= "{$content}"; |
||
| 229 | $ret .= "{$t}</p>{$n}"; |
||
| 230 | |||
| 231 | return $ret; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @public function getHtmlI |
||
| 236 | * @param string $content |
||
| 237 | * @param string $iClass |
||
| 238 | * @param string $t |
||
| 239 | * @param string $n |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getHtmlI($content = '', $iClass = '', $t = '', $n = "\n") |
||
| 243 | { |
||
| 244 | $rIClass = ('' != $iClass) ? " class='{$iClass}'" : ''; |
||
| 245 | $ret = "{$t}<i{$rIClass}>{$content}</i>{$n}"; |
||
| 246 | |||
| 247 | return $ret; |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @public function getHtmlUl |
||
| 252 | * @param string $content |
||
| 253 | * @param string $ulClass |
||
| 254 | * @param string $t |
||
| 255 | * @param string $n |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getHtmlUl($content = '', $ulClass = '', $t = '', $n = "\n") |
||
| 259 | { |
||
| 260 | $rUlClass = ('' != $ulClass) ? " class='{$ulClass}'" : ''; |
||
| 261 | $ret = "{$t}<ul{$rUlClass}>{$n}"; |
||
| 262 | $ret .= "{$content}"; |
||
| 263 | $ret .= "{$t}</ul>{$n}"; |
||
| 264 | |||
| 265 | return $ret; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @public function getHtmlOl |
||
| 270 | * @param string $content |
||
| 271 | * @param string $olClass |
||
| 272 | * @param string $t |
||
| 273 | * @param string $n |
||
| 274 | * @return string |
||
| 275 | */ |
||
| 276 | public function getHtmlOl($content = '', $olClass = '', $t = '', $n = "\n") |
||
| 277 | { |
||
| 278 | $rOlClass = ('' != $olClass) ? " class='{$olClass}'" : ''; |
||
| 279 | $ret = "{$t}<ol{$rOlClass}>{$n}"; |
||
| 280 | $ret .= "{$content}"; |
||
| 281 | $ret .= "{$t}</ol>{$n}"; |
||
| 282 | |||
| 283 | return $ret; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @public function getHtmlLi |
||
| 288 | * @param string $content |
||
| 289 | * @param string $liClass |
||
| 290 | * @param string $t |
||
| 291 | * @param string $n |
||
| 292 | * @param bool $split |
||
| 293 | * @return string |
||
| 294 | */ |
||
| 295 | public function getHtmlLi($content = '', $liClass = '', $t = '', $n = "\n", $split = false) |
||
| 296 | { |
||
| 297 | $rLiClass = ('' != $liClass) ? " class='{$liClass}'" : ''; |
||
| 298 | if ($split) { |
||
| 299 | $ret = "{$t}<li{$rLiClass}>{$n}"; |
||
| 300 | $ret .= "{$content}"; |
||
| 301 | $ret .= "{$t}</li>{$n}"; |
||
| 302 | } else { |
||
| 303 | $ret = "{$t}<li{$rLiClass}>{$content}</li>{$n}"; |
||
| 304 | } |
||
| 305 | |||
| 306 | return $ret; |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @public function getHtmlStrong |
||
| 311 | * @param string $content |
||
| 312 | * @param string $strongClass |
||
| 313 | * @param string $t |
||
| 314 | * @param string $n |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function getHtmlStrong($content = '', $strongClass = '', $t = '', $n = '') |
||
| 318 | { |
||
| 319 | $rStrongClass = ('' != $strongClass) ? " class='{$strongClass}'" : ''; |
||
| 320 | |||
| 321 | return "{$t}<strong{$rStrongClass}>{$content}</strong>{$n}"; |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @public function getHtmlAnchor |
||
| 326 | * @param string $url |
||
| 327 | * @param string $content |
||
| 328 | * @param string $title |
||
| 329 | * @param string $target |
||
| 330 | * @param string $aClass |
||
| 331 | * @param string $rel |
||
| 332 | * @param string $t |
||
| 333 | * @param string $n |
||
| 334 | * @return string |
||
| 335 | */ |
||
| 336 | public function getHtmlAnchor($url = '#', $content = ' ', $title = '', $target = '', $aClass = '', $rel = '', $t = '', $n = '') |
||
| 337 | { |
||
| 338 | $target = ('' != $target) ? " target='{$target}'" : ''; |
||
| 339 | $rAClass = ('' != $aClass) ? " class='{$aClass}'" : ''; |
||
| 340 | $rel = ('' != $rel) ? " rel='{$rel}'" : ''; |
||
| 341 | |||
| 342 | return "{$t}<a{$rAClass} href='{$url}' title='{$title}'{$target}{$rel}>{$content}</a>{$n}"; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @public function getHtmlImage |
||
| 347 | * @param string $src |
||
| 348 | * @param string $alt |
||
| 349 | * @param string $imgClass |
||
| 350 | * @param string $t |
||
| 351 | * @param string $n |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | public function getHtmlImage($src = 'blank.gif', $alt = 'blank.gif', $imgClass = '', $t = '', $n = '') |
||
| 355 | { |
||
| 356 | $rImgClass = ('' != $imgClass) ? " class='{$imgClass}'" : ''; |
||
| 357 | $ret = "{$t}<img{$rImgClass} src='{$src}' alt='{$alt}' />{$n}"; |
||
| 358 | |||
| 359 | return $ret; |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @public function getHtmlTable |
||
| 364 | * @param string $content |
||
| 365 | * @param string $tableClass |
||
| 366 | * @param string $t |
||
| 367 | * @param string $n |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function getHtmlTable($content = '', $tableClass = '', $t = '', $n = "\n") |
||
| 371 | { |
||
| 372 | $rTableClass = ('' != $tableClass) ? " class='{$tableClass}'" : ''; |
||
| 373 | $ret = "{$t}<table{$rTableClass}>{$n}"; |
||
| 374 | $ret .= "{$content}"; |
||
| 375 | $ret .= "{$t}</table>{$n}"; |
||
| 376 | |||
| 377 | return $ret; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @public function getHtmlTableThead |
||
| 382 | * @param string $content |
||
| 383 | * @param string $theadClass |
||
| 384 | * @param string $t |
||
| 385 | * @param string $n |
||
| 386 | * @return string |
||
| 387 | */ |
||
| 388 | public function getHtmlTableThead($content = '', $theadClass = '', $t = '', $n = "\n") |
||
| 389 | { |
||
| 390 | $rTheadClass = ('' != $theadClass) ? " class='{$theadClass}'" : ''; |
||
| 391 | $ret = "{$t}<thead{$rTheadClass}>{$n}"; |
||
| 392 | $ret .= "{$content}"; |
||
| 393 | $ret .= "{$t}</thead>{$n}"; |
||
| 394 | |||
| 395 | return $ret; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @public function getHtmlTableTbody |
||
| 400 | * @param string $content |
||
| 401 | * @param string $tbodyClass |
||
| 402 | * |
||
| 403 | * @param string $t |
||
| 404 | * @param string $n |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getHtmlTableTbody($content = '', $tbodyClass = '', $t = '', $n = "\n") |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @public function getHtmlTableTfoot |
||
| 419 | * @param string $content |
||
| 420 | * @param string $tfootClass |
||
| 421 | * |
||
| 422 | * @param string $t |
||
| 423 | * @param string $n |
||
| 424 | * @param bool $split |
||
| 425 | * @return string |
||
| 426 | */ |
||
| 427 | public function getHtmlTableTfoot($content = '', $tfootClass = '', $t = '', $n = "\n", $split = true) |
||
| 428 | { |
||
| 429 | $rTfootClass = ('' != $tfootClass) ? " class='{$tfootClass}'" : ''; |
||
| 430 | if ($split) { |
||
| 431 | $ret = "{$t}<tfoot{$rTfootClass}>{$n}"; |
||
| 432 | $ret .= "{$content}"; |
||
| 433 | $ret .= "{$t}</tfoot>{$n}"; |
||
| 434 | } else { |
||
| 435 | $ret = "{$t}<tfoot{$rTfootClass}>{$content}</tfoot>{$n}"; |
||
| 436 | } |
||
| 437 | |||
| 438 | return $ret; |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @public function getHtmlTableRow |
||
| 443 | * @param string $content |
||
| 444 | * @param string $trClass |
||
| 445 | * @param string $t |
||
| 446 | * @param string $n |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | public function getHtmlTableRow($content = '', $trClass = '', $t = '', $n = "\n") |
||
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @public function getHtmlTableHead |
||
| 461 | * @param string $content |
||
| 462 | * @param string $thClass |
||
| 463 | * @param string $colspan |
||
| 464 | * @param string $t |
||
| 465 | * @param string $n |
||
| 466 | * @param bool $split |
||
| 467 | * @return string |
||
| 468 | */ |
||
| 469 | public function getHtmlTableHead($content = '', $thClass = '', $colspan = '', $t = '', $n = "\n", $split = false) |
||
| 470 | { |
||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @public function getHtmlTableData |
||
| 485 | * @param string $content |
||
| 486 | * @param string $tdClass |
||
| 487 | * @param string $colspan |
||
| 488 | * @param string $t |
||
| 489 | * @param string $n |
||
| 490 | * @param bool $split |
||
| 491 | * @return string |
||
| 492 | */ |
||
| 493 | public function getHtmlTableData($content = '', $tdClass = '', $colspan = '', $t = '', $n = "\n", $split = false) |
||
| 505 | } |
||
| 506 | } |
||
| 507 |