StringHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B wrapInTag() 0 25 4
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Foo\Grid\Helper;
6
7
use Foo\Grid\Component\IComponent;
8
9
class StringHelper
10
{
11
    /**
12
     * @param string|IComponent $content
13
     * @param string|null       $tag
14
     * @param array             $attributes
15
     * @param string            $whitespace
16
     *
17
     * @return string
18
     */
19 35
    public static function wrapInTag($content, string $tag = null, array $attributes = [], $whitespace = ''): string
20
    {
21 35
        if (null === $tag) {
22 5
            return (string)$content;
23
        }
24
25 33
        $attributeHtml = '';
26
27 33
        foreach ($attributes as $key => $value) {
28 30
            $attributeHtml .= sprintf(' %s="%s"', $key, $value);
29
        }
30
31 33
        if ($whitespace) {
32 1
            return sprintf(
33 1
                '%4$s<%1$s%3$s>%5$s%2$s%5$s%4$s</%1$s>',
34
                $tag,
35 1
                (string)$content,
36
                $attributeHtml,
37
                $whitespace,
38 1
                "\n"
39
            );
40
        }
41
42 32
        return sprintf('<%1$s%3$s>%2$s</%1$s>', $tag, (string)$content, $attributeHtml);
43
    }
44
}
45