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 SimpleHtmlDomBlank extends AbstractSimpleHtmlDom implements \IteratorAggregate, SimpleHtmlDomInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param string $name |
16
|
|
|
* @param array $arguments |
17
|
|
|
* |
18
|
|
|
* @throws \BadMethodCallException |
19
|
|
|
* |
20
|
|
|
* @return SimpleHtmlDomInterface|string|null |
21
|
|
|
*/ |
22
|
1 |
|
public function __call($name, $arguments) |
23
|
|
|
{ |
24
|
1 |
|
$name = \strtolower($name); |
25
|
|
|
|
26
|
1 |
|
if (isset(self::$functionAliases[$name])) { |
27
|
1 |
|
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 SimpleHtmlDomNodeInterface |
40
|
|
|
*/ |
41
|
|
|
public function find(string $selector, $idx = null) |
42
|
|
|
{ |
43
|
|
|
return new SimpleHtmlDomNodeBlank(); |
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
|
2 |
|
public function getAttribute(string $name): string |
72
|
|
|
{ |
73
|
2 |
|
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 outer html. |
90
|
|
|
* |
91
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
1 |
|
public function html(bool $multiDecodeNewHtmlEntity = false): string |
96
|
|
|
{ |
97
|
1 |
|
return ''; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get dom node's inner html. |
102
|
|
|
* |
103
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
1 |
|
public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string |
108
|
|
|
{ |
109
|
1 |
|
return ''; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Remove attribute. |
114
|
|
|
* |
115
|
|
|
* @param string $name <p>The name of the html-attribute.</p> |
116
|
|
|
* |
117
|
|
|
* @return SimpleHtmlDomInterface |
118
|
|
|
*/ |
119
|
|
|
public function removeAttribute(string $name): SimpleHtmlDomInterface |
120
|
|
|
{ |
121
|
|
|
return $this; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
protected function replaceChildWithString(string $string): SimpleHtmlDomInterface |
125
|
|
|
{ |
126
|
2 |
|
return new static(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
protected function replaceNodeWithString(string $string): SimpleHtmlDomInterface |
130
|
|
|
{ |
131
|
|
|
return new static(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
protected function replaceTextWithString($string): SimpleHtmlDomInterface |
135
|
|
|
{ |
136
|
|
|
return new static(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set attribute value. |
141
|
|
|
* |
142
|
|
|
* @param string $name <p>The name of the html-attribute.</p> |
143
|
|
|
* @param string|null $value <p>Set to NULL or empty string, to remove the attribute.</p> |
144
|
|
|
* @param bool $strict </p> |
145
|
|
|
* $value must be NULL, to remove the attribute, |
146
|
|
|
* so that you can set an empty string as attribute-value e.g. autofocus="" |
147
|
|
|
* </p> |
148
|
|
|
* |
149
|
|
|
* @return SimpleHtmlDomInterface |
150
|
|
|
*/ |
151
|
1 |
|
public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface |
152
|
|
|
{ |
153
|
1 |
|
return $this; |
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get dom node's plain text. |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
3 |
|
public function text(): string |
162
|
|
|
{ |
163
|
3 |
|
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 SimpleHtmlDomNodeInterface |
184
|
|
|
*/ |
185
|
|
|
public function findMulti(string $selector): SimpleHtmlDomNodeInterface |
186
|
|
|
{ |
187
|
|
|
return new SimpleHtmlDomNodeBlank(); |
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 SimpleHtmlDomInterface |
208
|
|
|
*/ |
209
|
|
|
public function findOne(string $selector): SimpleHtmlDomInterface |
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 SimpleHtmlDomNodeInterface |
242
|
|
|
*/ |
243
|
|
|
public function getElementByClass(string $class): SimpleHtmlDomNodeInterface |
244
|
|
|
{ |
245
|
|
|
return new SimpleHtmlDomNodeBlank(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Return element by #id. |
250
|
|
|
* |
251
|
|
|
* @param string $id |
252
|
|
|
* |
253
|
|
|
* @return SimpleHtmlDomInterface |
254
|
|
|
*/ |
255
|
|
|
public function getElementById(string $id): SimpleHtmlDomInterface |
256
|
|
|
{ |
257
|
|
|
return new static(); |
|
|
|
|
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Return element by tag name. |
262
|
|
|
* |
263
|
|
|
* @param string $name |
264
|
|
|
* |
265
|
|
|
* @return SimpleHtmlDomInterface |
266
|
|
|
*/ |
267
|
|
|
public function getElementByTagName(string $name): SimpleHtmlDomInterface |
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 SimpleHtmlDomNodeInterface |
279
|
|
|
*/ |
280
|
|
|
public function getElementsById(string $id, $idx = null) |
281
|
|
|
{ |
282
|
|
|
return new SimpleHtmlDomNodeBlank(); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Returns elements by tag name. |
287
|
|
|
* |
288
|
|
|
* @param string $name |
289
|
|
|
* @param int|null $idx |
290
|
|
|
* |
291
|
|
|
* @return SimpleHtmlDomNodeInterface |
292
|
|
|
*/ |
293
|
|
|
public function getElementsByTagName(string $name, $idx = null) |
294
|
|
|
{ |
295
|
|
|
return new SimpleHtmlDomNodeBlank(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Create a new "HtmlDomParser"-object from the current context. |
300
|
|
|
* |
301
|
|
|
* @return HtmlDomParser |
302
|
|
|
*/ |
303
|
|
|
public function getHtmlDomParser(): HtmlDomParser |
304
|
|
|
{ |
305
|
|
|
return new HtmlDomParser($this); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @return \DOMNode |
310
|
|
|
*/ |
311
|
|
|
public function getNode(): \DOMNode |
312
|
|
|
{ |
313
|
|
|
return new \DOMNode(); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Nodes can get partially destroyed in which they're still an |
318
|
|
|
* actual DOM node (such as \DOMElement) but almost their entire |
319
|
|
|
* body is gone, including the `nodeType` attribute. |
320
|
|
|
* |
321
|
|
|
* @return bool true if node has been destroyed |
322
|
|
|
*/ |
323
|
|
|
public function isRemoved(): bool |
324
|
|
|
{ |
325
|
|
|
return true; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Returns the last child of node. |
330
|
|
|
* |
331
|
|
|
* @return null |
332
|
|
|
*/ |
333
|
|
|
public function lastChild() |
334
|
|
|
{ |
335
|
|
|
return null; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Returns the next sibling of node. |
340
|
|
|
* |
341
|
|
|
* @return null |
342
|
|
|
*/ |
343
|
|
|
public function nextSibling() |
344
|
|
|
{ |
345
|
|
|
return null; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Returns the next sibling of node. |
350
|
|
|
* |
351
|
|
|
* @return null |
352
|
|
|
*/ |
353
|
|
|
public function nextNonWhitespaceSibling() |
354
|
|
|
{ |
355
|
|
|
return null; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Returns the parent of node. |
360
|
|
|
* |
361
|
|
|
* @return SimpleHtmlDomInterface |
362
|
|
|
*/ |
363
|
|
|
public function parentNode(): SimpleHtmlDomInterface |
364
|
|
|
{ |
365
|
|
|
return new static(); |
|
|
|
|
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Returns the previous sibling of node. |
370
|
|
|
* |
371
|
|
|
* @return null |
372
|
|
|
*/ |
373
|
|
|
public function previousSibling() |
374
|
|
|
{ |
375
|
|
|
return null; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @param string|string[]|null $value <p> |
380
|
|
|
* null === get the current input value |
381
|
|
|
* text === set a new input value |
382
|
|
|
* </p> |
383
|
|
|
* |
384
|
|
|
* @return string|string[]|null |
385
|
|
|
*/ |
386
|
|
|
public function val($value = null) |
387
|
|
|
{ |
388
|
|
|
return null; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Retrieve an external iterator. |
393
|
|
|
* |
394
|
|
|
* @see http://php.net/manual/en/iteratoraggregate.getiterator.php |
395
|
|
|
* |
396
|
|
|
* @return SimpleHtmlDomNodeInterface |
397
|
|
|
* <p> |
398
|
|
|
* An instance of an object implementing <b>Iterator</b> or |
399
|
|
|
* <b>Traversable</b> |
400
|
|
|
* </p> |
401
|
|
|
*/ |
402
|
1 |
|
public function getIterator(): SimpleHtmlDomNodeInterface |
403
|
|
|
{ |
404
|
1 |
|
return new SimpleHtmlDomNodeBlank(); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Get dom node's inner xml. |
409
|
|
|
* |
410
|
|
|
* @param bool $multiDecodeNewHtmlEntity |
411
|
|
|
* |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
|
|
public function innerXml(bool $multiDecodeNewHtmlEntity = false): string |
415
|
|
|
{ |
416
|
|
|
return ''; |
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.