Passed
Push — master ( 4674d5...c94053 )
by Goffy
40s queued 13s
created

CreateHtmlCode   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 417
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 107
dl 0
loc 417
rs 5.04
c 0
b 0
f 0
wmc 57

25 Methods

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

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\Tdmcreate\Files;
4
5
use XoopsModules\Tdmcreate;
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
 * tdmcreate module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
/**
29
 * Class CreateHtmlCode.
30
 */
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 bool   $noBreak
57
     * @param string $t
58
     * @return string
59
     */
60
    public function getHtmlTag($tag = '', $attributes = [], $content = '', $noClosed = false, $noBreak = false, $t = '')
61
    {
62
        if (empty($attributes)) {
63
            $attributes = [];
64
        }
65
        $attr = $this->getAttributes($attributes);
66
        if ('br' === $tag) {
67
            $ret = "{$t}<{$tag}{$attr}>\n";
68
        } elseif ($noClosed) {
69
            $ret = "{$t}<{$tag}{$attr} />\n";
70
        } elseif ($noBreak) {
71
            $ret = "{$t}<{$tag}{$attr}>{$content}</{$tag}>\n";
72
        } else {
73
            $ret = "{$t}<{$tag}{$attr}>\n";
74
            $ret .= "{$t}{$content}";
75
            $ret .= "{$t}</{$tag}>\n";
76
        }
77
78
        return $ret;
79
    }
80
81
    /**
82
     * @private function setAttributes
83
     * @param array $attributes
84
     *
85
     * @return string
86
     */
87
    private function getAttributes($attributes)
88
    {
89
        $str = '';
90
        foreach ($attributes as $name => $value) {
91
            if ('_' !== $name) {
92
                $str .= ' ' . $name . '="' . $value . '"';
93
            }
94
        }
95
96
        return $str;
97
    }
98
99
    /**
100
     * @public function getHtmlEmpty
101
     * @param string $empty
102
     *
103
     * @return string
104
     */
105
    public function getHtmlEmpty($empty = '')
106
    {
107
        return (string)$empty;
108
    }
109
110
    /**
111
     * @public function getHtmlComment
112
     * @param string $htmlComment
113
     * @return string
114
     */
115
    public function getHtmlComment($htmlComment = '')
116
    {
117
        return "<!-- {$htmlComment} -->";
118
    }
119
120
    /**
121
     * @public function getHtmlBr
122
     * @param int    $brNumb
123
     * @param string $htmlClass
124
     * @param string $t
125
     * @return string
126
     */
127
    public function getHtmlBr($brNumb = 1, $htmlClass = '', $t = '')
128
    {
129
        $brClass = ('' != $htmlClass) ? " class='{$htmlClass}'" : '';
130
        $ret     = '';
131
        for ($i = 0; $i < $brNumb; ++$i) {
132
            $ret .= "{$t}<br{$brClass} />\n";
133
        }
134
135
        return $ret;
136
    }
137
138
    /**
139
     * @public function getHtmlHNumb
140
     * @param string $content
141
     * @param string $n
142
     * @param string $htmlHClass
143
     * @param string $t
144
     * @return string
145
     */
146
    public function getHtmlHNumb($content = '', $n = '1', $htmlHClass = '', $t = '')
147
    {
148
        $hClass = ('' != $htmlHClass) ? " class='{$htmlHClass}'" : '';
149
        $ret    = "{$t}<h{$n}{$hClass}>{$content}</h{$n}>\n";
150
151
        return $ret;
152
    }
153
154
    /**
155
     * @public function getHtmlDiv
156
     * @param string $content
157
     * @param string $divClass
158
     * @param string $t
159
     * @return string
160
     */
161
    public function getHtmlDiv($content = '', $divClass = '', $t = '')
162
    {
163
        $rDivClass = ('' != $divClass) ? " class='{$divClass}'" : '';
164
        $ret       = "{$t}<div{$rDivClass}>\n";
165
        $ret       .= "{$t}{$content}";
166
        $ret       .= "{$t}</div>\n";
167
168
        return $ret;
169
    }
170
171
    /**
172
     * @public function getHtmlPre
173
     * @param string $content
174
     * @param string $preClass
175
     * @param string $t
176
     * @return string
177
     */
178
    public function getHtmlPre($content = '', $preClass = '', $t = '')
179
    {
180
        $rPreClass = ('' != $preClass) ? " class='{$preClass}'" : '';
181
        $ret       = "{$t}<pre{$rPreClass}>\n";
182
        $ret       .= "{$t}{$content}";
183
        $ret       .= "{$t}</pre>\n";
184
185
        return $ret;
186
    }
187
188
    /**
189
     * @public function getHtmlSpan
190
     * @param string $content
191
     * @param string $spanClass
192
     * @param string $t
193
     * @return string
194
     */
195
    public function getHtmlSpan($content = '', $spanClass = '', $t = '')
196
    {
197
        $rSpanClass = ('' != $spanClass) ? " class='{$spanClass}'" : '';
198
        $ret        = "{$t}<span{$rSpanClass}>{$content}</span>\n";
199
200
        return $ret;
201
    }
202
203
    /**
204
     * @public function getHtmlParagraph
205
     * @param string $content
206
     * @param string $pClass
207
     * @param string $t
208
     * @return string
209
     */
210
    public function getHtmlParagraph($content = '', $pClass = '', $t = '')
211
    {
212
        $rPClass = ('' != $pClass) ? " class='{$pClass}'" : '';
213
        $ret     = "{$t}<p{$rPClass}>\n";
214
        $ret     .= "{$t}{$content}";
215
        $ret     .= "{$t}</p>\n";
216
217
        return $ret;
218
    }
219
220
    /**
221
     * @public function getHtmlI
222
     * @param string $content
223
     * @param string $iClass
224
     * @param string $t
225
     * @return string
226
     */
227
    public function getHtmlI($content = '', $iClass = '', $t = '')
228
    {
229
        $rIClass = ('' != $iClass) ? " class='{$iClass}'" : '';
230
        $ret     = "{$t}<i{$rIClass}>{$content}</i>";
231
232
        return $ret;
233
    }
234
235
    /**
236
     * @public function getHtmlUl
237
     * @param string $content
238
     * @param string $ulClass
239
     * @param string $t
240
     * @return string
241
     */
242
    public function getHtmlUl($content = '', $ulClass = '', $t = '')
243
    {
244
        $rUlClass = ('' != $ulClass) ? " class='{$ulClass}'" : '';
245
        $ret      = "{$t}<ul{$rUlClass}>\n";
246
        $ret      .= "{$t}{$content}";
247
        $ret      .= "{$t}</ul>\n";
248
249
        return $ret;
250
    }
251
252
    /**
253
     * @public function getHtmlOl
254
     * @param string $content
255
     * @param string $olClass
256
     * @param string $t
257
     * @return string
258
     */
259
    public function getHtmlOl($content = '', $olClass = '', $t = '')
260
    {
261
        $rOlClass = ('' != $olClass) ? " class='{$olClass}'" : '';
262
        $ret      = "{$t}<ol{$rOlClass}>\n";
263
        $ret      .= "{$t}{$content}";
264
        $ret      .= "{$t}</ol>\n";
265
266
        return $ret;
267
    }
268
269
    /**
270
     * @public function getHtmlLi
271
     * @param string $content
272
     * @param string $liClass
273
     * @param string $t
274
     * @return string
275
     */
276
    public function getHtmlLi($content = '', $liClass = '', $t = '')
277
    {
278
        $rLiClass = ('' != $liClass) ? " class='{$liClass}'" : '';
279
280
        return "{$t}<li{$rLiClass}>{$content}</li>\n";
281
    }
282
283
    /**
284
     * @public function getHtmlStrong
285
     * @param string $content
286
     * @param string $strongClass
287
     * @param string $t
288
     * @return string
289
     */
290
    public function getHtmlStrong($content = '', $strongClass = '', $t = '')
291
    {
292
        $rStrongClass = ('' != $strongClass) ? " class='{$strongClass}'" : '';
293
294
        return "{$t}<strong{$rStrongClass}>{$content}</strong>\n";
295
    }
296
297
    /**
298
     * @public function getHtmlAnchor
299
     * @param string $url
300
     * @param string $content
301
     * @param string $title
302
     * @param string $target
303
     * @param string $aClass
304
     * @param string $rel
305
     * @param string $t
306
     * @return string
307
     */
308
    public function getHtmlAnchor($url = '#', $content = '&nbsp;', $title = '', $target = '', $aClass = '', $rel = '', $t = '')
309
    {
310
        $target  = ('' != $target) ? " target='{$target}'" : '';
311
        $rAClass = ('' != $aClass) ? " class='{$aClass}'" : '';
312
        $rel     = ('' != $rel) ? " rel='{$rel}'" : '';
313
314
        return "{$t}<a{$rAClass} href='{$url}' title='{$title}'{$target}{$rel}>{$content}</a>\n";
315
    }
316
317
    /**
318
     * @public function getHtmlImage
319
     * @param string $src
320
     * @param string $alt
321
     * @param string $imgClass
322
     * @param string $t
323
     * @return string
324
     */
325
    public function getHtmlImage($src = 'blank.gif', $alt = 'blank.gif', $imgClass = '', $t = '')
326
    {
327
        $rImgClass = ('' != $imgClass) ? " class='{$imgClass}'" : '';
328
        $ret       = "{$t}<img{$rImgClass} src='{$src}' alt='{$alt}' />\n";
329
330
        return $ret;
331
    }
332
333
    /**
334
     * @public function getHtmlTable
335
     * @param string $content
336
     * @param string $tableClass
337
     * @param string $t
338
     * @return string
339
     */
340
    public function getHtmlTable($content = '', $tableClass = '', $t = '')
341
    {
342
        $rTableClass = ('' != $tableClass) ? " class='{$tableClass}'" : '';
343
        $ret         = "{$t}<table{$rTableClass}>\n";
344
        $ret         .= "{$t}{$content}";
345
        $ret         .= "{$t}</table>\n";
346
347
        return $ret;
348
    }
349
350
    /**
351
     * @public function getHtmlTableThead
352
     * @param string $content
353
     * @param string $theadClass
354
     * @param string $t
355
     * @return string
356
     */
357
    public function getHtmlTableThead($content = '', $theadClass = '', $t = '')
358
    {
359
        $rTheadClass = ('' != $theadClass) ? " class='{$theadClass}'" : '';
360
        $ret         = "{$t}\t<thead{$rTheadClass}>\n";
361
        $ret         .= "{$t}\t{$content}";
362
        $ret         .= "{$t}\t</thead>\n";
363
364
        return $ret;
365
    }
366
367
    /**
368
     * @public function getHtmlTableTbody
369
     * @param string $content
370
     * @param string $tbodyClass
371
     * @param string $t
372
     * @return string
373
     */
374
    public function getHtmlTableTbody($content = '', $tbodyClass = '', $t = '')
375
    {
376
        $rTbodyClass = ('' != $tbodyClass) ? " class='{$tbodyClass}'" : '';
377
        $ret         = "{$t}\t<tbody{$rTbodyClass}>\n";
378
        $ret         .= "{$t}\t{$content}";
379
        $ret         .= "{$t}\t</tbody>\n";
380
381
        return $ret;
382
    }
383
384
    /**
385
     * @public function getHtmlTableTfoot
386
     * @param string $content
387
     * @param string $tfootClass
388
     * @param string $t
389
     * @return string
390
     */
391
    public function getHtmlTableTfoot($content = '', $tfootClass = '', $t = '')
392
    {
393
        $rTfootClass = ('' != $tfootClass) ? " class='{$tfootClass}'" : '';
394
        $ret         = "{$t}\t<tfoot{$rTfootClass}>\n";
395
        $ret         .= "{$t}\t{$content}";
396
        $ret         .= "{$t}\t</tfoot>\n";
397
398
        return $ret;
399
    }
400
401
    /**
402
     * @public function getHtmlTableRow
403
     * @param string $content
404
     * @param string $trClass
405
     * @param string $t
406
     * @return string
407
     */
408
    public function getHtmlTableRow($content = '', $trClass = '', $t = '')
409
    {
410
        $rTrClass = ('' != $trClass) ? " class='{$trClass}'" : '';
411
        $ret      = "{$t}\t<tr{$rTrClass}>\n";
412
        $ret      .= "{$t}\t{$content}";
413
        $ret      .= "{$t}\t</tr>\n";
414
415
        return $ret;
416
    }
417
418
    /**
419
     * @public function getHtmlTableHead
420
     * @param string $content
421
     * @param string $thClass
422
     * @param string $colspan
423
     * @param string $t
424
     * @return string
425
     */
426
    public function getHtmlTableHead($content = '', $thClass = '', $colspan = '', $t = '')
427
    {
428
        $rThClass = ('' != $thClass) ? " class='{$thClass}'" : '';
429
        $colspan  = ('' != $colspan) ? " colspan='{$colspan}'" : '';
430
431
        return "{$t}<th{$colspan}{$rThClass}>{$content}</th>\n";
432
    }
433
434
    /**
435
     * @public function getHtmlTableData
436
     * @param string $content
437
     * @param string $tdClass
438
     * @param string $colspan
439
     * @param string $t
440
     * @return string
441
     */
442
    public function getHtmlTableData($content = '', $tdClass = '', $colspan = '', $t = '')
443
    {
444
        $rTdClass = ('' != $tdClass) ? " class='{$tdClass}'" : '';
445
        $colspan  = ('' != $colspan) ? " colspan='{$colspan}'" : '';
446
447
        return "{$t}<td{$colspan}{$rTdClass}>{$content}</td>\n";
448
    }
449
}
450