1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace voku\helper; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @noinspection PhpHierarchyChecksInspection |
9
|
|
|
* |
10
|
|
|
* {@inheritdoc} |
11
|
|
|
*/ |
12
|
|
View Code Duplication |
class SimpleXmlDomBlank extends AbstractSimpleXmlDom implements \IteratorAggregate, SimpleXmlDomInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param string $name |
16
|
|
|
* @param array $arguments |
17
|
|
|
* |
18
|
|
|
* @throws \BadMethodCallException |
19
|
|
|
* |
20
|
|
|
* @return SimpleXmlDomInterface|string|null |
21
|
|
|
*/ |
22
|
|
|
public function __call($name, $arguments) |
23
|
|
|
{ |
24
|
|
|
$name = \strtolower($name); |
25
|
|
|
|
26
|
|
|
if (isset(self::$functionAliases[$name])) { |
27
|
|
|
return \call_user_func_array([$this, self::$functionAliases[$name]], $arguments); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
throw new \BadMethodCallException('Method does not exist'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Find list of nodes with a CSS selector. |
35
|
|
|
* |
36
|
|
|
* @param string $selector |
37
|
|
|
* @param int|null $idx |
38
|
|
|
* |
39
|
|
|
* @return SimpleXmlDomNodeInterface |
40
|
|
|
*/ |
41
|
|
|
public function find(string $selector, $idx = null) |
42
|
|
|
{ |
43
|
|
|
return new SimpleXmlDomNodeBlank(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns an array of attributes. |
48
|
|
|
* |
49
|
|
|
* @return null |
50
|
|
|
*/ |
51
|
|
|
public function getAllAttributes() |
52
|
|
|
{ |
53
|
|
|
return null; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function hasAttributes(): bool |
60
|
|
|
{ |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return attribute value. |
66
|
|
|
* |
67
|
|
|
* @param string $name |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getAttribute(string $name): string |
72
|
|
|
{ |
73
|
|
|
return ''; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Determine if an attribute exists on the element. |
78
|
|
|
* |
79
|
|
|
* @param string $name |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function hasAttribute(string $name): bool |
84
|
|
|
{ |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get dom node's inner xml. |
90
|
|
|
* |
91
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function innerXml(bool $multiDecodeNewHtmlEntity = false): string |
96
|
|
|
{ |
97
|
|
|
return ''; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Remove attribute. |
102
|
|
|
* |
103
|
|
|
* @param string $name <p>The name of the html-attribute.</p> |
104
|
|
|
* |
105
|
|
|
* @return SimpleXmlDomInterface |
106
|
|
|
*/ |
107
|
|
|
public function removeAttribute(string $name): SimpleXmlDomInterface |
108
|
|
|
{ |
109
|
|
|
return $this; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function replaceChildWithString(string $string): SimpleXmlDomInterface |
113
|
|
|
{ |
114
|
|
|
return new static(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
protected function replaceNodeWithString(string $string): SimpleXmlDomInterface |
118
|
|
|
{ |
119
|
|
|
return new static(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function replaceTextWithString($string): SimpleXmlDomInterface |
123
|
|
|
{ |
124
|
|
|
return new static(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Set attribute value. |
129
|
|
|
* |
130
|
|
|
* @param string $name <p>The name of the html-attribute.</p> |
131
|
|
|
* @param string|null $value <p>Set to NULL or empty string, to remove the attribute.</p> |
132
|
|
|
* @param bool $strict </p> |
133
|
|
|
* $value must be NULL, to remove the attribute, |
134
|
|
|
* so that you can set an empty string as attribute-value e.g. autofocus="" |
135
|
|
|
* </p> |
136
|
|
|
* |
137
|
|
|
* @return SimpleXmlDomInterface |
138
|
|
|
*/ |
139
|
|
|
public function setAttribute(string $name, $value = null, bool $strict = false): SimpleXmlDomInterface |
140
|
|
|
{ |
141
|
|
|
return $this; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get dom node's plain text. |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function text(): string |
150
|
|
|
{ |
151
|
|
|
return ''; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get dom node's outer html. |
156
|
|
|
* |
157
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function xml(bool $multiDecodeNewHtmlEntity = false): string |
162
|
|
|
{ |
163
|
|
|
return ''; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Returns children of node. |
168
|
|
|
* |
169
|
|
|
* @param int $idx |
170
|
|
|
* |
171
|
|
|
* @return null |
172
|
|
|
*/ |
173
|
|
|
public function childNodes(int $idx = -1) |
174
|
|
|
{ |
175
|
|
|
return null; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Find nodes with a CSS selector. |
180
|
|
|
* |
181
|
|
|
* @param string $selector |
182
|
|
|
* |
183
|
|
|
* @return SimpleXmlDomNodeInterface |
184
|
|
|
*/ |
185
|
|
|
public function findMulti(string $selector): SimpleXmlDomNodeInterface |
186
|
|
|
{ |
187
|
|
|
return new SimpleXmlDomNodeBlank(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Find nodes with a CSS selector or false, if no element is found. |
192
|
|
|
* |
193
|
|
|
* @param string $selector |
194
|
|
|
* |
195
|
|
|
* @return false |
196
|
|
|
*/ |
197
|
|
|
public function findMultiOrFalse(string $selector) |
198
|
|
|
{ |
199
|
|
|
return false; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Find one node with a CSS selector. |
204
|
|
|
* |
205
|
|
|
* @param string $selector |
206
|
|
|
* |
207
|
|
|
* @return SimpleXmlDomInterface |
208
|
|
|
*/ |
209
|
|
|
public function findOne(string $selector): SimpleXmlDomInterface |
210
|
|
|
{ |
211
|
|
|
return new static(); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Find one node with a CSS selector or false, if no element is found. |
216
|
|
|
* |
217
|
|
|
* @param string $selector |
218
|
|
|
* |
219
|
|
|
* @return false |
220
|
|
|
*/ |
221
|
|
|
public function findOneOrFalse(string $selector) |
222
|
|
|
{ |
223
|
|
|
return false; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Returns the first child of node. |
228
|
|
|
* |
229
|
|
|
* @return null |
230
|
|
|
*/ |
231
|
|
|
public function firstChild() |
232
|
|
|
{ |
233
|
|
|
return null; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Return elements by ".class". |
238
|
|
|
* |
239
|
|
|
* @param string $class |
240
|
|
|
* |
241
|
|
|
* @return SimpleXmlDomNodeInterface |
242
|
|
|
*/ |
243
|
|
|
public function getElementByClass(string $class): SimpleXmlDomNodeInterface |
244
|
|
|
{ |
245
|
|
|
return new SimpleXmlDomNodeBlank(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Return element by #id. |
250
|
|
|
* |
251
|
|
|
* @param string $id |
252
|
|
|
* |
253
|
|
|
* @return SimpleXmlDomInterface |
254
|
|
|
*/ |
255
|
|
|
public function getElementById(string $id): SimpleXmlDomInterface |
256
|
|
|
{ |
257
|
|
|
return new static(); |
|
|
|
|
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Return element by tag name. |
262
|
|
|
* |
263
|
|
|
* @param string $name |
264
|
|
|
* |
265
|
|
|
* @return SimpleXmlDomInterface |
266
|
|
|
*/ |
267
|
|
|
public function getElementByTagName(string $name): SimpleXmlDomInterface |
268
|
|
|
{ |
269
|
|
|
return new static(); |
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Returns elements by "#id". |
274
|
|
|
* |
275
|
|
|
* @param string $id |
276
|
|
|
* @param int|null $idx |
277
|
|
|
* |
278
|
|
|
* @return SimpleXmlDomNodeInterface |
279
|
|
|
*/ |
280
|
|
|
public function getElementsById(string $id, $idx = null) |
281
|
|
|
{ |
282
|
|
|
return new SimpleXmlDomNodeBlank(); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Returns elements by tag name. |
287
|
|
|
* |
288
|
|
|
* @param string $name |
289
|
|
|
* @param int|null $idx |
290
|
|
|
* |
291
|
|
|
* @return SimpleXmlDomNodeInterface |
292
|
|
|
*/ |
293
|
|
|
public function getElementsByTagName(string $name, $idx = null) |
294
|
|
|
{ |
295
|
|
|
return new SimpleXmlDomNodeBlank(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return \DOMNode |
300
|
|
|
*/ |
301
|
|
|
public function getNode(): \DOMNode |
302
|
|
|
{ |
303
|
|
|
return new \DOMNode(); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Create a new "XmlDomParser"-object from the current context. |
308
|
|
|
* |
309
|
|
|
* @return XmlDomParser |
310
|
|
|
*/ |
311
|
|
|
public function getXmlDomParser(): XmlDomParser |
312
|
|
|
{ |
313
|
|
|
return new XmlDomParser($this); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Get dom node's inner html. |
318
|
|
|
* |
319
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
320
|
|
|
* |
321
|
|
|
* @return string |
322
|
|
|
*/ |
323
|
|
|
public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string |
324
|
|
|
{ |
325
|
|
|
return ''; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Nodes can get partially destroyed in which they're still an |
330
|
|
|
* actual DOM node (such as \DOMElement) but almost their entire |
331
|
|
|
* body is gone, including the `nodeType` attribute. |
332
|
|
|
* |
333
|
|
|
* @return bool true if node has been destroyed |
334
|
|
|
*/ |
335
|
|
|
public function isRemoved(): bool |
336
|
|
|
{ |
337
|
|
|
return true; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Returns the last child of node. |
342
|
|
|
* |
343
|
|
|
* @return null |
344
|
|
|
*/ |
345
|
|
|
public function lastChild() |
346
|
|
|
{ |
347
|
|
|
return null; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns the next sibling of node. |
352
|
|
|
* |
353
|
|
|
* @return null |
354
|
|
|
*/ |
355
|
|
|
public function nextSibling() |
356
|
|
|
{ |
357
|
|
|
return null; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Returns the next sibling of node. |
362
|
|
|
* |
363
|
|
|
* @return null |
364
|
|
|
*/ |
365
|
|
|
public function nextNonWhitespaceSibling() |
366
|
|
|
{ |
367
|
|
|
return null; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Returns the parent of node. |
372
|
|
|
* |
373
|
|
|
* @return SimpleXmlDomInterface |
374
|
|
|
*/ |
375
|
|
|
public function parentNode(): SimpleXmlDomInterface |
376
|
|
|
{ |
377
|
|
|
return new static(); |
|
|
|
|
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Returns the previous sibling of node. |
382
|
|
|
* |
383
|
|
|
* @return null |
384
|
|
|
*/ |
385
|
|
|
public function previousSibling() |
386
|
|
|
{ |
387
|
|
|
return null; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @param string|string[]|null $value <p> |
392
|
|
|
* null === get the current input value |
393
|
|
|
* text === set a new input value |
394
|
|
|
* </p> |
395
|
|
|
* |
396
|
|
|
* @return string|string[]|null |
397
|
|
|
*/ |
398
|
|
|
public function val($value = null) |
399
|
|
|
{ |
400
|
|
|
return null; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Retrieve an external iterator. |
405
|
|
|
* |
406
|
|
|
* @see http://php.net/manual/en/iteratoraggregate.getiterator.php |
407
|
|
|
* |
408
|
|
|
* @return SimpleXmlDomNodeInterface |
409
|
|
|
* <p> |
410
|
|
|
* An instance of an object implementing <b>Iterator</b> or |
411
|
|
|
* <b>Traversable</b> |
412
|
|
|
* </p> |
413
|
|
|
*/ |
414
|
|
|
public function getIterator(): SimpleXmlDomNodeInterface |
415
|
|
|
{ |
416
|
|
|
return new SimpleXmlDomNodeBlank(); |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.