Conditions | 8 |
Paths | 17 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 8 |
Changes | 0 |
1 | <?php |
||
18 | 9 | public static function renderElement(Element $element, int $currentDepth = 0): string |
|
19 | { |
||
20 | 9 | if ($currentDepth++ > self::RECURSION_LIMIT) { |
|
21 | 2 | throw new RecursionException('Recursion limit of ' . self::RECURSION_LIMIT . ' Reached'); |
|
22 | } |
||
23 | |||
24 | 9 | $elementContent = null; |
|
25 | 9 | foreach ($element->getChildElements() as $childElement) { |
|
26 | 4 | $elementContent .= str_repeat(self::INDENTING_CHAR, $currentDepth) . self::renderElement($childElement, $currentDepth); |
|
27 | } |
||
28 | |||
29 | 7 | if (null !== $element->getTextContent()) { |
|
30 | 1 | $elementContent .= str_repeat(self::INDENTING_CHAR, $currentDepth) . $element->getTextContent()->getContent() . PHP_EOL; |
|
31 | } |
||
32 | |||
33 | 7 | $attributeString = AttributeRenderer::renderAttributes($element->getAttributes()); |
|
34 | 7 | if (null === $elementContent && $element->canSelfClose()) { |
|
35 | 3 | return '<' . $element->getTagName() . (null !== $attributeString ? ' ' . $attributeString : null) . '/>' . PHP_EOL; |
|
36 | } |
||
37 | |||
38 | 5 | return '<' . $element->getTagName() . (null !== $attributeString ? ' ' . $attributeString : null) . '>' . PHP_EOL . |
|
39 | 5 | $elementContent . |
|
40 | 5 | str_repeat(self::INDENTING_CHAR, $currentDepth - 1) . '</' . $element->getTagName() . '>' . PHP_EOL; |
|
41 | } |
||
43 |