Test Failed
Branch v5 (12d602)
by Alexey
04:51
created

Html::el()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 6
nop 4
dl 0
loc 22
rs 6.9811
c 0
b 0
f 0
1
<?php
2
namespace Inji;
3
/**
4
 * Html
5
 * 
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class Html {
12
13
    /**
14
     * Generate html element
15
     * 
16
     * @param string $tag
17
     * @param array $attributes
18
     * @param string $body
19
     * @param boolean|null $noCloseTag
20
     * @return string
21
     */
22
    public static function el($tag, $attributes = [], $body = '', $noCloseTag = false) {
23
        $html = "<{$tag}";
24
        if (!empty($attributes) && is_array($attributes)) {
25
            foreach ($attributes as $key => $value) {
26
                $html .= " {$key} = '";
27
                if (!is_array($value)) {
28
                    $html .= addcslashes($value, "'");
29
                } else {
30
                    $html .= json_encode($value);
31
                }
32
                $html .= "'";
33
            }
34
        }
35
        if ($noCloseTag === null) {
36
            $html .= ' />';
37
        } elseif ($noCloseTag === false) {
38
            $html .= ">{$body}</{$tag}>";
39
        } else {
40
            $html .= ">{$body}";
41
        }
42
        return $html;
43
    }
44
45
}
46