Passed
Push — master ( 6251ab...a07882 )
by Thierry
01:53
created

DomTreeTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 132
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A domStartResponse() 0 3 1
A domEndResponse() 0 3 1
A domInsertAfter() 0 4 1
A domRemoveChildren() 0 4 1
A domAppendChild() 0 4 1
A domCreateElement() 0 4 1
A domAppendText() 0 4 1
A domInsertBefore() 0 4 1
A domSetAttribute() 0 4 1
1
<?php
2
3
/**
4
 * DomTreeTrait.php - Provides DOM (HTML) related commands for the Response
5
 *
6
 * @author Thierry Feuzeu <[email protected]>
7
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
8
 * @link https://github.com/jaxon-php/jaxon-core
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
10
11
namespace Jaxon\Response\Traits;
12
13
use Jaxon\Response\Response;
14
15
trait DomTreeTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait DomTreeTrait
Loading history...
16
{
17
    /**
18
     * Add a response command to the array of commands that will be sent to the browser
19
     *
20
     * @param string $sName    The command name
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 4 found
Loading history...
21
     * @param array $aAttributes    Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
22
     * @param mixed $mData    The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 4 found
Loading history...
23
     * @param bool $bRemoveEmpty    If true, remove empty attributes
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
24
     *
25
     * @return Response
26
     */
27
    abstract protected function _addCommand(string $sName, array $aAttributes, $mData, bool $bRemoveEmpty = false): Response;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
28
29
    /**
30
     * Add a command to start a DOM response
31
     *
32
     * @return Response
33
     */
34
    public function domStartResponse(): Response
35
    {
36
        return $this->_addCommand('DSR', [], '');
37
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
    /**
40
     * Add a command to create a DOM element
41
     *
42
     * @param string $sVariable    The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
43
     * @param string $sTag    The HTML tag of the new DOM element
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
44
     *
45
     * @return Response
46
     */
47
    public function domCreateElement(string $sVariable, string $sTag): Response
48
    {
49
        $aAttributes = ['tgt' => $sVariable];
50
        return $this->_addCommand('DCE', $aAttributes, $sTag);
51
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
52
53
    /**
54
     * Add a command to set an attribute on a DOM element
55
     *
56
     * @param string $sVariable    The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
57
     * @param string $sKey    The name of the attribute
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
58
     * @param string $sValue    The value of the attribute
59
     *
60
     * @return Response
61
     */
62
    public function domSetAttribute(string $sVariable, string $sKey, string $sValue): Response
63
    {
64
        $aAttributes = ['tgt' => $sVariable, 'key' => $sKey];
65
        return $this->_addCommand('DSA', $aAttributes, $sValue);
66
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
67
68
    /**
69
     * Add a command to remove children from a DOM element
70
     *
71
     * @param string $sParent    The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
72
     * @param int $nSkip    The number of children to skip
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
73
     * @param int $nRemove    The number of children to remove
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
74
     *
75
     * @return Response
76
     */
77
    public function domRemoveChildren(string $sParent, int $nSkip = 0, int $nRemove = 0): Response
78
    {
79
        $aAttributes = ['skip' => $nSkip, 'remove' => $nRemove];
80
        return $this->_addCommand('DRC', $aAttributes, $sParent, true);
81
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
82
83
    /**
84
     * Add a command to append a child to a DOM element
85
     *
86
     * @param string $sParent    The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
87
     * @param string $sVariable    The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
88
     *
89
     * @return Response
90
     */
91
    public function domAppendChild(string $sParent, string $sVariable): Response
92
    {
93
        $aAttributes = ['par' => $sParent];
94
        return $this->_addCommand('DAC', $aAttributes, $sVariable);
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
96
97
    /**
98
     * Add a command to insert a DOM element before another
99
     *
100
     * @param string $sTarget    The DOM target element
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
101
     * @param string $sVariable    The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
102
     *
103
     * @return Response
104
     */
105
    public function domInsertBefore(string $sTarget, string $sVariable): Response
106
    {
107
        $aAttributes = ['tgt' => $sTarget];
108
        return $this->_addCommand('DIB', $aAttributes, $sVariable);
109
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
110
111
    /**
112
     * Add a command to insert a DOM element after another
113
     *
114
     * @param string $sTarget    The DOM target element
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
115
     * @param string $sVariable    The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
116
     *
117
     * @return Response
118
     */
119
    public function domInsertAfter(string $sTarget, string $sVariable): Response
120
    {
121
        $aAttributes = ['tgt' => $sTarget];
122
        return $this->_addCommand('DIA', $aAttributes, $sVariable);
123
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
124
125
    /**
126
     * Add a command to append a text to a DOM element
127
     *
128
     * @param string $sParent    The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
129
     * @param string $sText    The HTML text to append
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
130
     *
131
     * @return Response
132
     */
133
    public function domAppendText(string $sParent, string $sText): Response
134
    {
135
        $aAttributes = ['par' => $sParent];
136
        return $this->_addCommand('DAT', $aAttributes, $sText);
137
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
138
139
    /**
140
     * Add a command to end a DOM response
141
     *
142
     * @return Response
143
     */
144
    public function domEndResponse(): Response
145
    {
146
        return $this->_addCommand('DER', [], '');
147
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
148
}
149