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

Html   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C el() 0 22 7
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