Test Failed
Pull Request — dev (#1)
by Paweł
12:17
created

Html   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A a() 0 4 1
A tag() 0 14 4
1
<?php
2
3
namespace pjpawel\Magis\Helper;
4
5
/**
6
 * @author Paweł Podgórski <[email protected]>
7
 */
8
class Html
9
{
10
11
    public const OPEN_TAG = '<';
12
    public const END_TAG = '>';
13
    public const VALUE_OPEN_END_TAG = '</';
14
15
    public static function a(string $href, ?string $value = null, array $properties = []): string
16
    {
17
        $properties['href'] = $href;
18
        return self::tag('a', $value, $properties);
19
    }
20
21
    public static function tag(string $name, ?string $value = null, array|string $properties = []): string
22
    {
23
        if (is_array($properties)) {
0 ignored issues
show
introduced by
The condition is_array($properties) is always true.
Loading history...
24
            $propertiesTransformed = [];
25
            foreach ($properties as $key => $property) {
26
                $propertiesTransformed[] = $key . '="' . $property . '"';
27
            }
28
            $properties = implode(' ', $propertiesTransformed);
29
        }
30
        $tag = self::OPEN_TAG . $name . ' ' . $properties . self::END_TAG;
31
        if ($value !== null) {
32
            $tag .= $value . self::VALUE_OPEN_END_TAG . $name . self::END_TAG;
33
        }
34
        return $tag;
35
    }
36
37
}