Test Setup Failed
Branch feature/code_improvement (b0d56f)
by Thierry
02:54
created

DomTreeCommands::domRemoveChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 8
c 0
b 0
f 0
cc 1
nop 3
rs 10
1
<?php
2
3
/**
4
 * DomTreeCommands.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\Features;
12
13
trait DomTreeCommands
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait DomTreeCommands
Loading history...
14
{
15
    /**
16
     * Add a response command to the array of commands that will be sent to the browser
17
     *
18
     * @param string        $sName              The command name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
19
     * @param array         $aAttributes        Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 8 found
Loading history...
20
     * @param mixed         $mData              The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
21
     * @param boolean       $bRemoveEmpty       If true, remove empty attributes
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
22
     *
23
     * @return Response
24
     */
25
    abstract protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false);
26
27
    /**
28
     * Add a command to start a DOM response
29
     *
30
     * @return Response
31
     */
32
    public function domStartResponse()
33
    {
34
        return $this->_addCommand('DSR', [], '');
35
    }
36
37
    /**
38
     * Add a command to create a DOM element
39
     *
40
     * @param string        $variable            The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
41
     * @param string        $tag                The HTML tag of the new DOM element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 16 found
Loading history...
42
     *
43
     * @return Response
44
     */
45
    public function domCreateElement($variable, $tag)
46
    {
47
        $aAttributes = ['tgt' => $variable];
48
        return $this->_addCommand('DCE', $aAttributes, $tag);
49
    }
50
51
    /**
52
     * Add a command to set an attribute on a DOM element
53
     *
54
     * @param string        $variable            The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
55
     * @param string        $key                The name of the attribute
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 16 found
Loading history...
56
     * @param string        $value                The value of the attribute
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 16 found
Loading history...
57
     *
58
     * @return Response
59
     */
60
    public function domSetAttribute($variable, $key, $value)
61
    {
62
        $aAttributes = [
63
            'tgt' => $variable,
64
            'key' => $key
65
        ];
66
        return $this->_addCommand('DSA', $aAttributes, $value);
67
    }
68
69
    /**
70
     * Add a command to remove children from a DOM element
71
     *
72
     * @param string        $parent             The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 13 found
Loading history...
73
     * @param string        $skip               The number of children to skip
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 15 found
Loading history...
74
     * @param string        $remove             The number of children to remove
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 13 found
Loading history...
75
     *
76
     * @return Response
77
     */
78
    public function domRemoveChildren($parent, $skip = '', $remove = '')
79
    {
80
        $aAttributes = [
81
            'skip' => $skip,
82
            'remove' => $remove
83
        ];
84
        return $this->_addCommand('DRC', $aAttributes, $parent, true);
85
    }
86
87
    /**
88
     * Add a command to append a child to a DOM element
89
     *
90
     * @param string        $parent                The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
91
     * @param string        $variable            The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
92
     *
93
     * @return Response
94
     */
95
    public function domAppendChild($parent, $variable)
96
    {
97
        $aAttributes = ['par' => $parent];
98
        return $this->_addCommand('DAC', $aAttributes, $variable);
99
    }
100
101
    /**
102
     * Add a command to insert a DOM element before another
103
     *
104
     * @param string        $target                The DOM target element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
105
     * @param string        $variable            The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
106
     *
107
     * @return Response
108
     */
109
    public function domInsertBefore($target, $variable)
110
    {
111
        $aAttributes = ['tgt' => $target];
112
        return $this->_addCommand('DIB', $aAttributes, $variable);
113
    }
114
115
    /**
116
     * Add a command to insert a DOM element after another
117
     *
118
     * @param string        $target                The DOM target element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
119
     * @param string        $variable            The DOM element name (id or class)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
120
     *
121
     * @return Response
122
     */
123
    public function domInsertAfter($target, $variable)
124
    {
125
        $aAttributes = ['tgt' => $target];
126
        return $this->_addCommand('DIA', $aAttributes, $variable);
127
    }
128
129
    /**
130
     * Add a command to append a text to a DOM element
131
     *
132
     * @param string        $parent                The DOM parent element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
133
     * @param string        $text                The HTML text to append
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
134
     *
135
     * @return Response
136
     */
137
    public function domAppendText($parent, $text)
138
    {
139
        $aAttributes = ['par' => $parent];
140
        return $this->_addCommand('DAT', $aAttributes, $text);
141
    }
142
143
    /**
144
     * Add a command to end a DOM response
145
     *
146
     * @return Response
147
     */
148
    public function domEndResponse()
149
    {
150
        return $this->_addCommand('DER', [], '');
151
    }
152
}
153