Html::attributes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebTheory\Html;
4
5
use WebTheory\Html\Traits\ElementConstructorTrait;
6
7
/**
8
 * @method static string div(string $inner = '', array $attributes = [])
9
 * @method static string span(string $inner = '', array $attributes = [])
10
 * @method static string main(string $inner = '', array $attributes = [])
11
 * @method static string form(string $inner = '', array $attributes = [])
12
 * @method static string h1(string $inner = '', array $attributes = [])
13
 * @method static string h2(string $inner = '', array $attributes = [])
14
 * @method static string h3(string $inner = '', array $attributes = [])
15
 * @method static string h4(string $inner = '', array $attributes = [])
16
 * @method static string h5(string $inner = '', array $attributes = [])
17
 * @method static string h6(string $inner = '', array $attributes = [])
18
 * @method static string input(array $attributes = [])
19
 */
20
class Html
21
{
22
    use ElementConstructorTrait {
23
        tag as public;
24
        open as public;
25
        close as public;
26
        maybeClose as public;
27
        tagIsVoid as public;
28
    }
29
30
    public static function __callStatic(string $tag, array $args): string
31
    {
32
        if (static::tagIsVoid($tag)) {
33
            $attributes = $args[0] ?? [];
34
            $html = static::tag($tag, $attributes);
35
        } else {
36
            $inner = $args[0] ?? '';
37
            $attributes = $args[1] ?? [];
38
            $html = static::tag($tag, $attributes, $inner);
39
        }
40
41
        return $html;
42
    }
43
44
    public static function attributes(array $attributes, bool $trim = true): string
45
    {
46
        $attributes = static::parseAttributes($attributes);
47
48
        return $trim ? ltrim($attributes) : $attributes;
49
    }
50
}
51