@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | - * Insert given element relative to this element's position |
|
36 | - * |
|
37 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
38 | - * @param DOMElement $element |
|
39 | - * @return DOMElement |
|
40 | - */ |
|
35 | + * Insert given element relative to this element's position |
|
36 | + * |
|
37 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
38 | + * @param DOMElement $element |
|
39 | + * @return DOMElement |
|
40 | + */ |
|
41 | 41 | public function insertAdjacentElement(string $where, DOMElement $element): DOMElement |
42 | 42 | { |
43 | 43 | $this->insertAdjacentNode($where, $element); |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Insert given XML relative to this element's position |
|
50 | - * |
|
51 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
52 | - * @param string $xml |
|
53 | - * @return void |
|
54 | - */ |
|
49 | + * Insert given XML relative to this element's position |
|
50 | + * |
|
51 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
52 | + * @param string $xml |
|
53 | + * @return void |
|
54 | + */ |
|
55 | 55 | public function insertAdjacentXML(string $where, string $xml): void |
56 | 56 | { |
57 | 57 | $fragment = $this->ownerDocument->createDocumentFragment(); |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | - * Remove this element from the document |
|
65 | - * |
|
66 | - * @return self This element |
|
67 | - */ |
|
64 | + * Remove this element from the document |
|
65 | + * |
|
66 | + * @return self This element |
|
67 | + */ |
|
68 | 68 | public function remove(): self |
69 | 69 | { |
70 | 70 | return $this->parentNode->removeChild($this); |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | - * Replace this element with given element |
|
75 | - * |
|
76 | - * @param DOMElement $element Replacement element |
|
77 | - * @return self This element |
|
78 | - */ |
|
74 | + * Replace this element with given element |
|
75 | + * |
|
76 | + * @param DOMElement $element Replacement element |
|
77 | + * @return self This element |
|
78 | + */ |
|
79 | 79 | public function replace(DOMElement $element): self |
80 | 80 | { |
81 | 81 | return $this->parentNode->replaceChild($element, $this); |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Add namespace declarations that may be missing in given XML |
|
86 | - * |
|
87 | - * @param string $xml Original XML |
|
88 | - * @return string Modified XML |
|
89 | - */ |
|
85 | + * Add namespace declarations that may be missing in given XML |
|
86 | + * |
|
87 | + * @param string $xml Original XML |
|
88 | + * @return string Modified XML |
|
89 | + */ |
|
90 | 90 | protected function addMissingNamespaceDeclarations(string $xml): string |
91 | 91 | { |
92 | 92 | preg_match_all('(xmlns:\\K[-\\w]++(?==))', $xml, $m); |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | - * Insert given node relative to this element's position |
|
119 | - * |
|
120 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
121 | - * @param DOMNode $node |
|
122 | - * @return void |
|
123 | - */ |
|
118 | + * Insert given node relative to this element's position |
|
119 | + * |
|
120 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
121 | + * @param DOMNode $node |
|
122 | + * @return void |
|
123 | + */ |
|
124 | 124 | protected function insertAdjacentNode(string $where, DOMNode $node): void |
125 | 125 | { |
126 | 126 | if ($where === 'beforebegin') |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $callback = [$this->ownerDocument, 'create' . $m[2]]; |
22 | 22 | if (is_callable($callback)) |
23 | 23 | { |
24 | - $element = call_user_func_array($callback, $arguments); |
|
24 | + $element = call_user_func_array($callback, $arguments); |
|
25 | 25 | $where = ($m[1] === 'append') ? 'beforeend' : 'afterbegin'; |
26 | 26 | |
27 | 27 | return $this->insertAdjacentElement($where, $element); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | return preg_replace_callback( |
96 | 96 | '(<([-\\w]++):[^>]++>)', |
97 | - function ($m) use ($prefixes) |
|
97 | + function($m) use ($prefixes) |
|
98 | 98 | { |
99 | 99 | $xml = $m[0]; |
100 | 100 | $prefix = $m[1]; |
@@ -126,20 +126,16 @@ |
||
126 | 126 | if ($where === 'beforebegin') |
127 | 127 | { |
128 | 128 | $this->parentNode->insertBefore($node, $this); |
129 | - } |
|
130 | - elseif ($where === 'beforeend') |
|
129 | + } elseif ($where === 'beforeend') |
|
131 | 130 | { |
132 | 131 | $this->appendChild($node); |
133 | - } |
|
134 | - elseif ($where === 'afterend') |
|
132 | + } elseif ($where === 'afterend') |
|
135 | 133 | { |
136 | 134 | $this->parentNode->insertBefore($node, $this->nextSibling); |
137 | - } |
|
138 | - elseif ($where === 'afterbegin') |
|
135 | + } elseif ($where === 'afterbegin') |
|
139 | 136 | { |
140 | 137 | $this->insertBefore($node, $this->firstChild); |
141 | - } |
|
142 | - else |
|
138 | + } else |
|
143 | 139 | { |
144 | 140 | throw new InvalidArgumentException; |
145 | 141 | } |
@@ -15,12 +15,12 @@ discard block |
||
15 | 15 | class Document extends DOMDocument |
16 | 16 | { |
17 | 17 | /** |
18 | - * @link https://www.php.net/manual/domdocument.construct.php |
|
19 | - * |
|
20 | - * @param string $version Version number of the document |
|
21 | - * @param string $encoding Encoding of the document |
|
22 | - * @return void |
|
23 | - */ |
|
18 | + * @link https://www.php.net/manual/domdocument.construct.php |
|
19 | + * |
|
20 | + * @param string $version Version number of the document |
|
21 | + * @param string $encoding Encoding of the document |
|
22 | + * @return void |
|
23 | + */ |
|
24 | 24 | public function __construct(string $version = '1.0', string $encoding = 'utf-8') |
25 | 25 | { |
26 | 26 | parent::__construct($version, $encoding); |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | - * Create and return an xsl:apply-templates element |
|
33 | - * |
|
34 | - * @param string $select XPath expression for the "select" attribute |
|
35 | - * @return Element |
|
36 | - */ |
|
32 | + * Create and return an xsl:apply-templates element |
|
33 | + * |
|
34 | + * @param string $select XPath expression for the "select" attribute |
|
35 | + * @return Element |
|
36 | + */ |
|
37 | 37 | public function createXslApplyTemplates(string $select = null): Element |
38 | 38 | { |
39 | 39 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:apply-templates'); |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Create and return an xsl:attribute element |
|
50 | - * |
|
51 | - * @param string $name Attribute's name |
|
52 | - * @param string $namespace Attribute's namespace URI |
|
53 | - * @return Element |
|
54 | - */ |
|
49 | + * Create and return an xsl:attribute element |
|
50 | + * |
|
51 | + * @param string $name Attribute's name |
|
52 | + * @param string $namespace Attribute's namespace URI |
|
53 | + * @return Element |
|
54 | + */ |
|
55 | 55 | public function createXslAttribute(string $name, string $namespace = null): Element |
56 | 56 | { |
57 | 57 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:attribute'); |
@@ -65,32 +65,32 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * Create and return an xsl:choose element |
|
69 | - * |
|
70 | - * @return Element |
|
71 | - */ |
|
68 | + * Create and return an xsl:choose element |
|
69 | + * |
|
70 | + * @return Element |
|
71 | + */ |
|
72 | 72 | public function createXslChoose(): Element |
73 | 73 | { |
74 | 74 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:choose'); |
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Create and return an xsl:comment element |
|
79 | - * |
|
80 | - * @param string $text Text content for the comment |
|
81 | - * @return Element |
|
82 | - */ |
|
78 | + * Create and return an xsl:comment element |
|
79 | + * |
|
80 | + * @param string $text Text content for the comment |
|
81 | + * @return Element |
|
82 | + */ |
|
83 | 83 | public function createXslComment(string $text = ''): Element |
84 | 84 | { |
85 | 85 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:comment', htmlspecialchars($text, ENT_XML1)); |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Create and return an xsl:copy-of element |
|
90 | - * |
|
91 | - * @param string $select XPath expression for the "select" attribute |
|
92 | - * @return Element |
|
93 | - */ |
|
89 | + * Create and return an xsl:copy-of element |
|
90 | + * |
|
91 | + * @param string $select XPath expression for the "select" attribute |
|
92 | + * @return Element |
|
93 | + */ |
|
94 | 94 | public function createXslCopyOf(string $select): Element |
95 | 95 | { |
96 | 96 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:copy-of'); |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Create and return an xsl:if element |
|
104 | - * |
|
105 | - * @param string $test XPath expression for the "test" attribute |
|
106 | - * @return Element |
|
107 | - */ |
|
103 | + * Create and return an xsl:if element |
|
104 | + * |
|
105 | + * @param string $test XPath expression for the "test" attribute |
|
106 | + * @return Element |
|
107 | + */ |
|
108 | 108 | public function createXslIf(string $test): Element |
109 | 109 | { |
110 | 110 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:if'); |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | - * Create and return an xsl:otherwise element |
|
118 | - * |
|
119 | - * @return Element |
|
120 | - */ |
|
117 | + * Create and return an xsl:otherwise element |
|
118 | + * |
|
119 | + * @return Element |
|
120 | + */ |
|
121 | 121 | public function createXslOtherwise(): Element |
122 | 122 | { |
123 | 123 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:otherwise'); |
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * Create and return an xsl:param element |
|
128 | - * |
|
129 | - * @param string $name Name of the parameter |
|
130 | - * @param string $select XPath expression |
|
131 | - * @return Element |
|
132 | - */ |
|
127 | + * Create and return an xsl:param element |
|
128 | + * |
|
129 | + * @param string $name Name of the parameter |
|
130 | + * @param string $select XPath expression |
|
131 | + * @return Element |
|
132 | + */ |
|
133 | 133 | public function createXslParam(string $name, string $select = null): Element |
134 | 134 | { |
135 | 135 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:param'); |
@@ -143,22 +143,22 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | - * Create and return an xsl:text element |
|
147 | - * |
|
148 | - * @param string $text Text content for the element |
|
149 | - * @return Element |
|
150 | - */ |
|
146 | + * Create and return an xsl:text element |
|
147 | + * |
|
148 | + * @param string $text Text content for the element |
|
149 | + * @return Element |
|
150 | + */ |
|
151 | 151 | public function createXslText(string $text = ''): Element |
152 | 152 | { |
153 | 153 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:text', htmlspecialchars($text, ENT_XML1)); |
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | - * Create and return an xsl:value-of element |
|
158 | - * |
|
159 | - * @param string $select XPath expression for the "select" attribute |
|
160 | - * @return Element |
|
161 | - */ |
|
157 | + * Create and return an xsl:value-of element |
|
158 | + * |
|
159 | + * @param string $select XPath expression for the "select" attribute |
|
160 | + * @return Element |
|
161 | + */ |
|
162 | 162 | public function createXslValueOf(string $select): Element |
163 | 163 | { |
164 | 164 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:value-of'); |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | - * Create and return an xsl:variable element |
|
172 | - * |
|
173 | - * @param string $name Name of the variable |
|
174 | - * @param string $select XPath expression |
|
175 | - * @return Element |
|
176 | - */ |
|
171 | + * Create and return an xsl:variable element |
|
172 | + * |
|
173 | + * @param string $name Name of the variable |
|
174 | + * @param string $select XPath expression |
|
175 | + * @return Element |
|
176 | + */ |
|
177 | 177 | public function createXslVariable(string $name, string $select = null): Element |
178 | 178 | { |
179 | 179 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:variable'); |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | - * Create and return an xsl:when element |
|
191 | - * |
|
192 | - * @param string $test XPath expression for the "test" attribute |
|
193 | - * @return Element |
|
194 | - */ |
|
190 | + * Create and return an xsl:when element |
|
191 | + * |
|
192 | + * @param string $test XPath expression for the "test" attribute |
|
193 | + * @return Element |
|
194 | + */ |
|
195 | 195 | public function createXslWhen(string $test): Element |
196 | 196 | { |
197 | 197 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:when'); |
@@ -201,39 +201,39 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
204 | - * Evaluate and return the result of a given XPath expression |
|
205 | - * |
|
206 | - * @param string $expr XPath expression |
|
207 | - * @param DOMNode $node Context node |
|
208 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
209 | - * @return mixed |
|
210 | - */ |
|
204 | + * Evaluate and return the result of a given XPath expression |
|
205 | + * |
|
206 | + * @param string $expr XPath expression |
|
207 | + * @param DOMNode $node Context node |
|
208 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
209 | + * @return mixed |
|
210 | + */ |
|
211 | 211 | public function evaluate(string $expr, DOMNode $node = null, bool $registerNodeNS = true) |
212 | 212 | { |
213 | 213 | return call_user_func_array([$this->xpath(), 'evaluate'], func_get_args()); |
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | - * Evaluate and return the first element of a given XPath query |
|
218 | - * |
|
219 | - * @param string $expr XPath expression |
|
220 | - * @param DOMNode $node Context node |
|
221 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
222 | - * @return DOMNode|null |
|
223 | - */ |
|
217 | + * Evaluate and return the first element of a given XPath query |
|
218 | + * |
|
219 | + * @param string $expr XPath expression |
|
220 | + * @param DOMNode $node Context node |
|
221 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
222 | + * @return DOMNode|null |
|
223 | + */ |
|
224 | 224 | public function firstOf(string $expr, DOMNode $node = null, bool $registerNodeNS = true): ?DOMNode |
225 | 225 | { |
226 | 226 | return call_user_func_array([$this, 'query'], func_get_args())->item(0); |
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | - * Evaluate and return the result of a given XPath query |
|
231 | - * |
|
232 | - * @param string $expr XPath expression |
|
233 | - * @param DOMNode $node Context node |
|
234 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
235 | - * @return DOMNodeList |
|
236 | - */ |
|
230 | + * Evaluate and return the result of a given XPath query |
|
231 | + * |
|
232 | + * @param string $expr XPath expression |
|
233 | + * @param DOMNode $node Context node |
|
234 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
235 | + * @return DOMNodeList |
|
236 | + */ |
|
237 | 237 | public function query(string $expr, DOMNode $node = null, bool $registerNodeNS = true): DOMNodeList |
238 | 238 | { |
239 | 239 | return call_user_func_array([$this->xpath(), 'query'], func_get_args()); |