FormScript   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 10
dl 0
loc 37
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromXML() 0 6 1
A getHTML() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Formgenerator;
5
6
/**
7
 * Class to insert a script tag 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 FormScript extends FormElement
14
{
15
    /** @var string text for the line label     */
16
    protected string $strScript;
17
18
    /**
19
     * Cretae a script tag inside of the form.
20
     * @param string $strScript     Script to insert
21
     */
22
    public function __construct(string $strScript)
23
    {
24
        parent::__construct(0);
25
        $this->strScript = $strScript;
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     * @see \SKien\Formgenerator\FormElement::fromXML()
31
     * @internal
32
     */
33
    static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement
34
    {
35
        $strScript = $oXMLElement->textContent;
36
        $oFormElement = new self($strScript);
37
        $oFormParent->add($oFormElement);
38
        return $oFormElement;
39
    }
40
41
    /**
42
     * Insert the script at current position of the form.
43
     * @return string
44
     * @internal l
45
     */
46
    public function getHTML() : string
47
    {
48
        $strHTML = '<script>' . $this->strScript . '</script>' . PHP_EOL;
49
        return $strHTML;
50
    }
51
}
52