TWrappers   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addWrapper() 0 4 1
A formatData() 0 14 4
1
<?php
2
3
namespace kalanis\kw_table\core\Table\Columns;
4
5
6
/**
7
 * Trait TWrappers
8
 * @package kalanis\kw_table\core\Table\Columns
9
 */
10
trait TWrappers
11
{
12
    /** @var array<string, string|array<string, string>> */
13
    protected array $wrappers = [];
14
15
    /**
16
     * Add wrap tag
17
     * @param string $htmlTag
18
     * @param string|array<string, string> $attributes
19
     * @return $this
20
     */
21 1
    public function addWrapper(string $htmlTag, $attributes = '')
22
    {
23 1
        $this->wrappers[$htmlTag] = $attributes;
24 1
        return $this;
25
    }
26
27
    /**
28
     * Format data into tag with attributes
29
     * @param string $data
30
     * @return string
31
     */
32 3
    protected function formatData(string $data): string
33
    {
34 3
        foreach ($this->wrappers as $tag => $attribute) {
35 1
            if (is_array($attribute)) {
36 1
                $fill = '';
37 1
                foreach ($attribute as $k => $v) {
38 1
                    $fill .= sprintf('%s="%s"', $k, $v);
39
                }
40
            } else {
41 1
                $fill = $attribute;
42
            }
43 1
            $data = sprintf('<%s %s>%s</%s>', $tag, $fill, $data, $tag);
44
        }
45 3
        return $data;
46
    }
47
}
48