Passed
Push — develop ( 3be2c9...97f0fc )
by Felipe
04:52
created

XHtmlElement   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 24
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 13
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-RC8
5
 */
6
7
namespace PHPPgAdmin\XHtml;
8
9
/**
10
 *  XHtmlElement.
11
 *
12
 *  Used to generate Xhtml-Code for xhtml elements
13
 *  that can contain child elements
14
 */
15
class XHtmlElement extends XHtmlSimpleElement
16
{
17
    public $_text;
18
    public $_htmlcode = '';
19
    public $_siblings = [];
20
21
    public function __construct($text = null)
22
    {
23
        parent::__construct();
24
25
        if ($text) {
26
            $this->set_text($text);
27
        }
28
    }
29
30
    /*
31
     * Adds an xhtml child to element
32
     *
33
     * @param XHtmlElement $object    The element to become a child of element
34
     */
35
    public function add(&XHtmlOption $object)
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 35 at column 25
Loading history...
36
    {
37
        array_push($this->_siblings, $object);
38
    }
39
40
    /*
41
     * The CDATA section of Element
42
     *
43
     * @param    string   $text Text content of the element
44
     */
45
    public function set_text($text)
46
    {
47
        if ($text) {
48
            $this->_text = htmlspecialchars($text);
49
        }
50
    }
51
52
    public function fetch()
53
    {
54
        return $this->_html();
55
    }
56
57
    public function _html()
58
    {
59
        $this->_htmlcode = "<{$this->_element}";
60
        foreach ($this->_attributes as $attribute => $value) {
61
            if (!empty($value)) {
62
                $this->_htmlcode .= sprintf(' %s="%s" ', $attribute, $value);
63
            }
64
        }
65
        $this->_htmlcode .= '>';
66
67
        if ($this->_text) {
68
            $this->_htmlcode .= $this->_text;
69
        }
70
71
        foreach ($this->_siblings as $obj) {
72
            $this->_htmlcode .= $obj->fetch();
73
        }
74
75
        $this->_htmlcode .= "</{$this->_element}>";
76
77
        return $this->_htmlcode;
78
    }
79
80
    // Returns siblings of Element
81
    public function get_siblings()
82
    {
83
        return $this->_siblings;
84
    }
85
86
    public function has_siblings()
87
    {
88
        return 0 != count($this->_siblings);
89
    }
90
}
91