ElementContent::__toString()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 31
rs 8.439
cc 5
eloc 22
nc 8
nop 0
1
<?php
2
3
namespace hemio\html\Abstract_;
4
5
abstract class ElementContent extends Element implements \hemio\html\Interface_\MaintainsChilds
6
{
7
8
    use \hemio\html\Trait_\ChildMaintainance;
9
10
    /**
11
     *
12
     */
13
    public function __toString()
14
    {
15
        foreach ($this->hooksToString as $hook)
16
            $hook($this);
17
18
        $blnFormatted = true;
19
20
        if ($this->blnIsBlock() && $blnFormatted)
21
            $strNewLine = PHP_EOL;
22
        else
23
            $strNewLine = '';
24
25
        $strReturn = '';
26
27
        $strReturn .=
28
            '<'.static::tagName()
29
            .$this->getFormattedElementAttributes()
30
            .'>'
31
            .$strNewLine;
32
33
        foreach ($this as $child)
34
            $strReturn .= $child->__toString();
35
36
        $strReturn .=
37
            $strNewLine.
38
            '</'.static::tagName().
39
            '>'.
40
            $strNewLine;
41
42
        return $strReturn;
43
    }
44
45
    /**
46
     * Default assumption is, that an element is not a block element.
47
     * This might be overwritten by the implementation of a specific element.
48
     *
49
     * @return boolean
50
     */
51
    public function blnIsBlock()
52
    {
53
        return false;
54
    }
55
56
    public function describe()
57
    {
58
        return sprintf('%s(%d)', $this->tagName(), $this->count());
59
    }
60
}
61