Conditions | 4 |
Paths | 5 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
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 |