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