CreateHtmlCode   F
last analyzed

Complexity

Total Complexity 66

Size/Duplication

Total Lines 490
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 141
c 0
b 0
f 0
dl 0
loc 490
rs 3.12
wmc 66

25 Methods

Rating   Name   Duplication   Size   Complexity  
A getHtmlDiv() 0 13 3
A getAttributes() 0 10 3
A getHtmlTable() 0 8 2
A getHtmlSpan() 0 14 4
A getHtmlTableTfoot() 0 12 3
A getHtmlPre() 0 8 2
A getHtmlBr() 0 9 3
A getInstance() 0 8 2
A getHtmlAnchor() 0 7 4
A getHtmlEmpty() 0 3 1
A getHtmlTableRow() 0 8 2
A getHtmlTableData() 0 12 4
A getHtmlComment() 0 3 1
A getHtmlHNumb() 0 6 2
A getHtmlStrong() 0 5 2
A getHtmlTableThead() 0 8 2
A getHtmlTableTbody() 0 8 2
A getHtmlOl() 0 8 2
A getHtmlTag() 0 23 6
A getHtmlTableHead() 0 12 4
A getHtmlImage() 0 6 2
A getHtmlLi() 0 12 3
A getHtmlUl() 0 8 2
A getHtmlParagraph() 0 8 2
A getHtmlI() 0 7 3

How to fix   Complexity   

Complex Class

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
2
3
namespace XoopsModules\Modulebuilder\Files;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * modulebuilder module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops https://xoops.org 
25
 *                  Goffy https://myxoops.org
26
 *
27
 */
28
29
/**
30
 * Class CreateHtmlCode.
31
 */
32
class CreateHtmlCode
33
{
34
    /**
35
     * @static function getInstance
36
     *
37
     * @param null
38
     *
39
     * @return CreateHtmlCode
40
     */
41
    public static function getInstance()
42
    {
43
        static $instance = false;
44
        if (!$instance) {
45
            $instance = new self();
46
        }
47
48
        return $instance;
49
    }
50
51
    /**
52
     * @public function getHtmlTag
53
     * @param string $tag
54
     * @param array $attributes
55
     * @param string $content
56
     * @param bool $noClosed
57
     * @param string $t
58
     * @param string $n
59
     * @param bool $multiLine
60
     * @return string
61
     */
62
    public function getHtmlTag($tag = '', $attributes = [], $content = '', $noClosed = false, $t = '', $n = "\n", $multiLine = false)
63
    {
64
        if (empty($attributes)) {
65
            $attributes = [];
66
        }
67
        $attr = $this->getAttributes($attributes);
68
        if ('br' === $tag) {
69
            $ret = "{$t}<{$tag}{$attr}>{$n}";
70
        } elseif ($noClosed) {
71
            if ('img' === $tag) {
72
                $ret = "{$t}<{$tag}{$attr} >{$n}";
73
            } else {
74
                $ret = "{$t}<{$tag}{$attr} />{$n}";
75
            }
76
		} elseif ($multiLine) {
77
            $ret = "{$t}<{$tag}{$attr}>{$n}";
78
            $ret .= "{$content}";
79
            $ret .= "{$t}</{$tag}>{$n}";
80
        } else {
81
            $ret = "{$t}<{$tag}{$attr}>{$content}</{$tag}>{$n}";
82
        }
83
84
        return $ret;
85
    }
86
87
    /**
88
     * @private function setAttributes
89
     * @param array $attributes
90
     * @return string
91
     */
92
    private function getAttributes($attributes)
93
    {
94
        $str = '';
95
        foreach ($attributes as $name => $value) {
96
            if ('_' !== $name) {
97
                $str .= ' ' . $name . '="' . $value . '"';
98
            }
99
        }
100
101
        return $str;
102
    }
103
104
    /**
105
     * @public function getHtmlEmpty
106
     * @param string $empty
107
     * @param string $t
108
     * @param string $n
109
     * @return string
110
     */
111
    public function getHtmlEmpty($empty = '', $t = '', $n = '')
112
    {
113
        return "{$t}{$empty}{$n}";
114
    }
115
116
    /**
117
     * @public function getHtmlComment
118
     * @param string $htmlComment
119
     * @param string $t
120
     * @param string $n
121
     * @return string
122
     */
123
    public function getHtmlComment($htmlComment = '', $t = '', $n = '')
124
    {
125
        return "{$t}<!-- {$htmlComment} -->{$n}";
126
    }
127
128
    /**
129
     * @public function getHtmlBr
130
     * @param int $brNumb
131
     * @param string $htmlClass
132
     * @param string $t
133
     * @param string $n
134
     * @return string
135
     */
136
    public function getHtmlBr($brNumb = 1, $htmlClass = '', $t = '', $n = "\n")
137
    {
138
        $brClass = ('' != $htmlClass) ? " class='{$htmlClass}'" : '';
139
        $ret     = '';
140
        for ($i = 0; $i < $brNumb; ++$i) {
141
            $ret .= "{$t}<br{$brClass}>{$n}";
142
        }
143
144
        return $ret;
145
    }
146
147
    /**
148
     * @public function getHtmlHNumb
149
     * @param string $content
150
     * @param string $l
151
     * @param string $htmlHClass
152
     * @param string $t
153
     * @param string $n
154
     * @return string
155
     */
156
    public function getHtmlHNumb($content = '', $l = '1', $htmlHClass = '', $t = '', $n = "\n")
157
    {
158
        $hClass = ('' != $htmlHClass) ? " class='{$htmlHClass}'" : '';
159
        $ret    = "{$t}<h{$l}{$hClass}>{$content}</h{$l}>{$n}";
160
161
        return $ret;
162
    }
163
164
    /**
165
     * @public function getHtmlDiv
166
     * @param string $content
167
     * @param string $divClass
168
     * @param string $t
169
     * @param string $n
170
     * @param bool $split
171
     * @return string
172
     */
173
    public function getHtmlDiv($content = '', $divClass = '', $t = '', $n = "\n", $split = true)
174
    {
175
        $rDivClass = ('' != $divClass) ? " class='{$divClass}'" : '';
176
177
        if ($split) {
178
            $ret       = "{$t}<div{$rDivClass}>{$n}";
179
            $ret       .= "{$content}";
180
            $ret       .= "{$t}</div>{$n}";
181
        } else {
182
            $ret       = "{$t}<div{$rDivClass}>{$content}</div>{$n}";
183
        }
184
185
        return $ret;
186
    }
187
188
    /**
189
     * @public function getHtmlPre
190
     * @param string $content
191
     * @param string $preClass
192
     * @param string $t
193
     * @param string $n
194
     * @return string
195
     */
196
    public function getHtmlPre($content = '', $preClass = '', $t = '', $n = "\n")
197
    {
198
        $rPreClass = ('' != $preClass) ? " class='{$preClass}'" : '';
199
        $ret       = "{$t}<pre{$rPreClass}>{$n}";
200
        $ret       .= "{$content}";
201
        $ret       .= "{$t}</pre>{$n}";
202
203
        return $ret;
204
    }
205
206
    /**
207
     * @public function getHtmlSpan
208
     * @param string $content
209
     * @param string $spanClass
210
     * @param string $t
211
     * @param string $n
212
     * @param bool $split
213
     * @return string
214
     */
215
    public function getHtmlSpan($content = '', $spanClass = '', $t = '', $n = "\n", $split = false)
216
    {
217
        $rSpanClass = ('' != $spanClass) ? " class='{$spanClass}'" : '';
218
        $ret        = "{$t}<span{$rSpanClass}>";
219
        if ($split) {
220
            $ret .= "\n";
221
        }
222
        $ret .= "{$content}";
223
        if ($split) {
224
            $ret .= "\n{$t}";
225
        }
226
        $ret .= "</span>{$n}";
227
228
        return $ret;
229
    }
230
231
    /**
232
     * @public function getHtmlParagraph
233
     * @param string $content
234
     * @param string $pClass
235
     * @param string $t
236
     * @param string $n
237
     * @return string
238
     */
239
    public function getHtmlParagraph($content = '', $pClass = '', $t = '', $n = "\n")
240
    {
241
        $rPClass = ('' != $pClass) ? " class='{$pClass}'" : '';
242
        $ret     = "{$t}<p{$rPClass}>{$n}";
243
        $ret     .= "{$content}";
244
        $ret     .= "{$t}</p>{$n}";
245
246
        return $ret;
247
    }
248
249
    /**
250
     * @public function getHtmlI
251
     * @param string $content
252
     * @param string $iClass
253
     * @param string $iId
254
     * @param string $t
255
     * @param string $n
256
     * @return string
257
     */
258
    public function getHtmlI($content = '', $iClass = '', $iId = '', $t = '', $n = "\n")
259
    {
260
        $rIClass = ('' != $iClass) ? " class='{$iClass}'" : '';
261
        $rIId     = ('' != $iId) ? " id='{$iId}'" : '';
262
        $ret     = "{$t}<i{$rIClass}{$rIId}>{$content}</i>{$n}";
263
264
        return $ret;
265
    }
266
267
    /**
268
     * @public function getHtmlUl
269
     * @param string $content
270
     * @param string $ulClass
271
     * @param string $t
272
     * @param string $n
273
     * @return string
274
     */
275
    public function getHtmlUl($content = '', $ulClass = '', $t = '', $n = "\n")
276
    {
277
        $rUlClass = ('' != $ulClass) ? " class='{$ulClass}'" : '';
278
        $ret      = "{$t}<ul{$rUlClass}>{$n}";
279
        $ret      .= "{$content}";
280
        $ret      .= "{$t}</ul>{$n}";
281
282
        return $ret;
283
    }
284
285
    /**
286
     * @public function getHtmlOl
287
     * @param string $content
288
     * @param string $olClass
289
     * @param string $t
290
     * @param string $n
291
     * @return string
292
     */
293
    public function getHtmlOl($content = '', $olClass = '', $t = '', $n = "\n")
294
    {
295
        $rOlClass = ('' != $olClass) ? " class='{$olClass}'" : '';
296
        $ret      = "{$t}<ol{$rOlClass}>{$n}";
297
        $ret      .= "{$content}";
298
        $ret      .= "{$t}</ol>{$n}";
299
300
        return $ret;
301
    }
302
303
    /**
304
     * @public function getHtmlLi
305
     * @param string $content
306
     * @param string $liClass
307
     * @param string $t
308
     * @param string $n
309
     * @param bool $split
310
     * @return string
311
     */
312
    public function getHtmlLi($content = '', $liClass = '', $t = '', $n = "\n",  $split = false)
313
    {
314
        $rLiClass = ('' != $liClass) ? " class='{$liClass}'" : '';
315
        if ($split) {
316
            $ret       = "{$t}<li{$rLiClass}>{$n}";
317
            $ret       .= "{$content}";
318
            $ret       .= "{$t}</li>{$n}";
319
        } else {
320
            $ret       = "{$t}<li{$rLiClass}>{$content}</li>{$n}";
321
        }
322
323
        return $ret;
324
    }
325
326
    /**
327
     * @public function getHtmlStrong
328
     * @param string $content
329
     * @param string $strongClass
330
     * @param string $t
331
     * @param string $n
332
     * @return string
333
     */
334
    public function getHtmlStrong($content = '', $strongClass = '', $t = '', $n = '')
335
    {
336
        $rStrongClass = ('' != $strongClass) ? " class='{$strongClass}'" : '';
337
338
        return "{$t}<strong{$rStrongClass}>{$content}</strong>{$n}";
339
    }
340
341
	/**
342
     * @public function getHtmlAnchor
343
     * @param string $url
344
     * @param string $content
345
     * @param string $title
346
     * @param string $target
347
     * @param string $aClass
348
     * @param string $rel
349
     * @param string $t
350
     * @param string $n
351
     * @return string
352
     */
353
    public function getHtmlAnchor($url = '#', $content = '&nbsp;', $title = '', $target = '', $aClass = '', $rel = '', $t = '', $n = '')
354
    {
355
        $target  = ('' != $target) ? " target='{$target}'" : '';
356
        $rAClass = ('' != $aClass) ? " class='{$aClass}'" : '';
357
        $rel     = ('' != $rel) ? " rel='{$rel}'" : '';
358
359
        return "{$t}<a{$rAClass} href='{$url}' title='{$title}'{$target}{$rel}>{$content}</a>{$n}";
360
    }
361
362
    /**
363
     * @public function getHtmlImage
364
     * @param string $src
365
     * @param string $alt
366
     * @param string $imgClass
367
     * @param string $t
368
	 * @param string $n
369
     * @return string
370
     */
371
    public function getHtmlImage($src = 'blank.gif', $alt = 'blank.gif', $imgClass = '', $t = '', $n = '')
372
    {
373
        $rImgClass = ('' != $imgClass) ? " class='{$imgClass}'" : '';
374
        $ret       = "{$t}<img{$rImgClass} src='{$src}' alt='{$alt}' >{$n}";
375
376
        return $ret;
377
    }
378
379
    /**
380
     * @public function getHtmlTable
381
     * @param string $content
382
     * @param string $tableClass
383
     * @param string $t
384
     * @param string $n
385
     * @return string
386
     */
387
    public function getHtmlTable($content = '', $tableClass = '', $t = '', $n = "\n")
388
    {
389
        $rTableClass = ('' != $tableClass) ? " class='{$tableClass}'" : '';
390
        $ret         = "{$t}<table{$rTableClass}>{$n}";
391
        $ret         .= "{$content}";
392
        $ret         .= "{$t}</table>{$n}";
393
394
        return $ret;
395
    }
396
397
    /**
398
     * @public function getHtmlTableThead
399
     * @param string $content
400
     * @param string $theadClass
401
     * @param string $t
402
     * @param string $n
403
     * @return string
404
     */
405
    public function getHtmlTableThead($content = '', $theadClass = '', $t = '', $n = "\n")
406
    {
407
        $rTheadClass = ('' != $theadClass) ? " class='{$theadClass}'" : '';
408
        $ret         = "{$t}<thead{$rTheadClass}>{$n}";
409
        $ret         .= "{$content}";
410
        $ret         .= "{$t}</thead>{$n}";
411
412
        return $ret;
413
    }
414
415
    /**
416
     * @public function getHtmlTableTbody
417
     * @param string $content
418
     * @param string $tbodyClass
419
     *
420
     * @param string $t
421
     * @param string $n
422
     * @return string
423
     */
424
    public function getHtmlTableTbody($content = '', $tbodyClass = '', $t = '', $n = "\n")
425
    {
426
        $rTbodyClass = ('' != $tbodyClass) ? " class='{$tbodyClass}'" : '';
427
        $ret         = "{$t}<tbody{$rTbodyClass}>{$n}";
428
        $ret         .= "{$content}";
429
        $ret         .= "{$t}</tbody>{$n}";
430
431
        return $ret;
432
    }
433
434
    /**
435
     * @public function getHtmlTableTfoot
436
     * @param string $content
437
     * @param string $tfootClass
438
     *
439
     * @param string $t
440
     * @param string $n
441
     * @param bool $split
442
     * @return string
443
     */
444
    public function getHtmlTableTfoot($content = '', $tfootClass = '', $t = '', $n = "\n", $split = true)
445
    {
446
        $rTfootClass = ('' != $tfootClass) ? " class='{$tfootClass}'" : '';
447
        if ($split) {
448
            $ret         = "{$t}<tfoot{$rTfootClass}>{$n}";
449
            $ret         .= "{$content}";
450
            $ret         .= "{$t}</tfoot>{$n}";
451
        } else {
452
            $ret         = "{$t}<tfoot{$rTfootClass}>{$content}</tfoot>{$n}";
453
        }
454
455
        return $ret;
456
    }
457
458
    /**
459
     * @public function getHtmlTableRow
460
     * @param string $content
461
     * @param string $trClass
462
     * @param string $t
463
     * @param string $n
464
     * @return string
465
     */
466
    public function getHtmlTableRow($content = '', $trClass = '', $t = '', $n = "\n")
467
    {
468
        $rTrClass = ('' != $trClass) ? " class='{$trClass}'" : '';
469
        $ret      = "{$t}<tr{$rTrClass}>{$n}";
470
        $ret      .= "{$content}";
471
        $ret      .= "{$t}</tr>{$n}";
472
473
        return $ret;
474
    }
475
476
    /**
477
     * @public function getHtmlTableHead
478
     * @param string $content
479
     * @param string $thClass
480
     * @param string $colspan
481
     * @param string $t
482
     * @param string $n
483
     * @param bool $split
484
     * @return string
485
     */
486
    public function getHtmlTableHead($content = '', $thClass = '', $colspan = '', $t = '', $n = "\n", $split = false)
487
    {
488
        $rThClass = ('' != $thClass) ? " class='{$thClass}'" : '';
489
        $colspan  = ('' != $colspan) ? " colspan='{$colspan}'" : '';
490
        if ($split) {
491
            $ret      = "{$t}<th{$colspan}{$rThClass}>{$n}";
492
            $ret      .= "{$content}";
493
            $ret      .= "{$t}</th>{$n}";
494
        } else {
495
            $ret = "{$t}<th{$colspan}{$rThClass}>{$content}</th>{$n}";
496
        }
497
        return $ret;
498
    }
499
500
    /**
501
     * @public function getHtmlTableData
502
     * @param string $content
503
     * @param string $tdClass
504
     * @param string $colspan
505
     * @param string $t
506
     * @param string $n
507
     * @param bool $split
508
     * @return string
509
     */
510
    public function getHtmlTableData($content = '', $tdClass = '', $colspan = '', $t = '', $n = "\n", $split = false)
511
    {
512
        $rTdClass = ('' != $tdClass) ? " class='{$tdClass}'" : '';
513
        $colspan  = ('' != $colspan) ? " colspan='{$colspan}'" : '';
514
        if ($split) {
515
            $ret      = "{$t}<td{$colspan}{$rTdClass}>{$n}";
516
            $ret      .= "{$content}";
517
            $ret      .= "{$t}</td>{$n}";
518
        } else {
519
            $ret = "{$t}<td{$colspan}{$rTdClass}>{$content}</td>{$n}";
520
        }
521
        return $ret;
522
    }
523
}
524