FormHeader::getHTML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Formgenerator;
5
6
/**
7
 * Class to display a header line inside of the form.
8
 *
9
 * @package Formgenerator
10
 * @author Stefanius <[email protected]>
11
 * @copyright MIT License - see the LICENSE file for details
12
 */
13
class FormHeader extends FormElement
14
{
15
    /** @var string text for the header     */
16
    protected string $strText;
17
    /** @var int level of the HTML header element     */
18
    protected int $iLevel;
19
20
    /**
21
     * Create header element.
22
     * @param string $strText   Text to display
23
     * @param int $iLevel    level of the header (&lt;h1&gt; ... &lt;h5&gt;)
24
     */
25
    public function __construct(string $strText, $iLevel = 2)
26
    {
27
        parent::__construct(0);
28
        $this->strText = $strText;
29
        $this->iLevel = $iLevel;
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     * @see \SKien\Formgenerator\FormElement::fromXML()
35
     * @internal
36
     */
37
    static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement
38
    {
39
        $strText = self::getAttribString($oXMLElement, 'text');
40
        $iLevel = self::getAttribInt($oXMLElement, 'level', 2);
41
        $oFormElement = new self($strText, $iLevel);
42
        $oFormParent->add($oFormElement);
43
        $oFormElement->readAdditionalXML($oXMLElement);
44
45
        return $oFormElement;
46
    }
47
48
    /**
49
     * Build the HTML-notation for the header text
50
     * @return string
51
     * @internal
52
     */
53
    public function getHTML() : string
54
    {
55
        $strHTML = '<h' . $this->iLevel . '>' . $this->strText . '</h' . $this->iLevel . '>' . PHP_EOL;
56
        return $strHTML;
57
    }
58
}
59