Code Duplication    Length = 389-401 lines in 2 locations

src/voku/helper/SimpleHtmlDomBlank.php 1 location

@@ 8-396 (lines=389) @@
5
namespace voku\helper;
6
7
/** @noinspection PhpHierarchyChecksInspection */
8
class SimpleHtmlDomBlank extends AbstractSimpleHtmlDom implements \IteratorAggregate, SimpleHtmlDomInterface
9
{
10
    /**
11
     * @param string $name
12
     * @param array  $arguments
13
     *
14
     * @throws \BadMethodCallException
15
     *
16
     * @return SimpleHtmlDomInterface|string|null
17
     */
18
    public function __call($name, $arguments)
19
    {
20
        $name = \strtolower($name);
21
22
        if (isset(self::$functionAliases[$name])) {
23
            return \call_user_func_array([$this, self::$functionAliases[$name]], $arguments);
24
        }
25
26
        throw new \BadMethodCallException('Method does not exist');
27
    }
28
29
    /**
30
     * Find list of nodes with a CSS selector.
31
     *
32
     * @param string   $selector
33
     * @param int|null $idx
34
     *
35
     * @return SimpleHtmlDomNodeInterface
36
     */
37
    public function find(string $selector, $idx = null)
38
    {
39
        return new SimpleHtmlDomNodeBlank();
40
    }
41
42
    /**
43
     * Returns an array of attributes.
44
     *
45
     * @return null
46
     */
47
    public function getAllAttributes()
48
    {
49
        return null;
50
    }
51
52
    /**
53
     * Return attribute value.
54
     *
55
     * @param string $name
56
     *
57
     * @return string
58
     */
59
    public function getAttribute(string $name): string
60
    {
61
        return '';
62
    }
63
64
    /**
65
     * Determine if an attribute exists on the element.
66
     *
67
     * @param string $name
68
     *
69
     * @return bool
70
     */
71
    public function hasAttribute(string $name): bool
72
    {
73
        return false;
74
    }
75
76
    /**
77
     * Get dom node's outer html.
78
     *
79
     * @param bool $multiDecodeNewHtmlEntity
80
     *
81
     * @return string
82
     */
83
    public function html(bool $multiDecodeNewHtmlEntity = false): string
84
    {
85
        return '';
86
    }
87
88
    /**
89
     * Get dom node's inner html.
90
     *
91
     * @param bool $multiDecodeNewHtmlEntity
92
     *
93
     * @return string
94
     */
95
    public function innerHtml(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 SimpleHtmlDomInterface
106
     */
107
    public function removeAttribute(string $name): SimpleHtmlDomInterface
108
    {
109
        return $this;
110
    }
111
112
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
113
    {
114
        return new static();
115
    }
116
117
    protected function replaceNodeWithString(string $string): SimpleHtmlDomInterface
118
    {
119
        return new static();
120
    }
121
122
    protected function replaceTextWithString($string): SimpleHtmlDomInterface
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 SimpleHtmlDomInterface
138
     */
139
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface
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
     * Returns children of node.
156
     *
157
     * @param int $idx
158
     *
159
     * @return null
160
     */
161
    public function childNodes(int $idx = -1)
162
    {
163
        return null;
164
    }
165
166
    /**
167
     * Find nodes with a CSS selector.
168
     *
169
     * @param string $selector
170
     *
171
     * @return SimpleHtmlDomNodeInterface
172
     */
173
    public function findMulti(string $selector): SimpleHtmlDomNodeInterface
174
    {
175
        return new SimpleHtmlDomNodeBlank();
176
    }
177
178
    /**
179
     * Find nodes with a CSS selector or false, if no element is found.
180
     *
181
     * @param string $selector
182
     *
183
     * @return false
184
     */
185
    public function findMultiOrFalse(string $selector)
186
    {
187
        return false;
188
    }
189
190
    /**
191
     * Find one node with a CSS selector.
192
     *
193
     * @param string $selector
194
     *
195
     * @return SimpleHtmlDomInterface
196
     */
197
    public function findOne(string $selector): SimpleHtmlDomInterface
198
    {
199
        return new static();
200
    }
201
202
    /**
203
     * Find one node with a CSS selector or false, if no element is found.
204
     *
205
     * @param string $selector
206
     *
207
     * @return false
208
     */
209
    public function findOneOrFalse(string $selector)
210
    {
211
        return false;
212
    }
213
214
    /**
215
     * Returns the first child of node.
216
     *
217
     * @return null
218
     */
219
    public function firstChild()
220
    {
221
        return null;
222
    }
223
224
    /**
225
     * Return elements by .class.
226
     *
227
     * @param string $class
228
     *
229
     * @return SimpleHtmlDomNodeInterface
230
     */
231
    public function getElementByClass(string $class): SimpleHtmlDomNodeInterface
232
    {
233
        return new SimpleHtmlDomNodeBlank();
234
    }
235
236
    /**
237
     * Return element by #id.
238
     *
239
     * @param string $id
240
     *
241
     * @return SimpleHtmlDomInterface
242
     */
243
    public function getElementById(string $id): SimpleHtmlDomInterface
244
    {
245
        return new static();
246
    }
247
248
    /**
249
     * Return element by tag name.
250
     *
251
     * @param string $name
252
     *
253
     * @return SimpleHtmlDomInterface
254
     */
255
    public function getElementByTagName(string $name): SimpleHtmlDomInterface
256
    {
257
        return new static();
258
    }
259
260
    /**
261
     * Returns elements by #id.
262
     *
263
     * @param string   $id
264
     * @param int|null $idx
265
     *
266
     * @return SimpleHtmlDomNodeInterface
267
     */
268
    public function getElementsById(string $id, $idx = null)
269
    {
270
        return new SimpleHtmlDomNodeBlank();
271
    }
272
273
    /**
274
     * Returns elements by tag name.
275
     *
276
     * @param string   $name
277
     * @param int|null $idx
278
     *
279
     * @return SimpleHtmlDomNodeInterface
280
     */
281
    public function getElementsByTagName(string $name, $idx = null)
282
    {
283
        return new SimpleHtmlDomNodeBlank();
284
    }
285
286
    /**
287
     * Create a new "HtmlDomParser"-object from the current context.
288
     *
289
     * @return HtmlDomParser
290
     */
291
    public function getHtmlDomParser(): HtmlDomParser
292
    {
293
        return new HtmlDomParser($this);
294
    }
295
296
    /**
297
     * @return \DOMNode
298
     */
299
    public function getNode(): \DOMNode
300
    {
301
        return new \DOMNode();
302
    }
303
304
    /**
305
     * Nodes can get partially destroyed in which they're still an
306
     * actual DOM node (such as \DOMElement) but almost their entire
307
     * body is gone, including the `nodeType` attribute.
308
     *
309
     * @return bool true if node has been destroyed
310
     */
311
    public function isRemoved(): bool
312
    {
313
        return true;
314
    }
315
316
    /**
317
     * Returns the last child of node.
318
     *
319
     * @return null
320
     */
321
    public function lastChild()
322
    {
323
        return null;
324
    }
325
326
    /**
327
     * Returns the next sibling of node.
328
     *
329
     * @return null
330
     */
331
    public function nextSibling()
332
    {
333
        return null;
334
    }
335
336
    /**
337
     * Returns the parent of node.
338
     *
339
     * @return SimpleHtmlDomInterface
340
     */
341
    public function parentNode(): SimpleHtmlDomInterface
342
    {
343
        return new static();
344
    }
345
346
    /**
347
     * Returns the previous sibling of node.
348
     *
349
     * @return null
350
     */
351
    public function previousSibling()
352
    {
353
        return null;
354
    }
355
356
    /**
357
     * @param string|string[]|null $value <p>
358
     *                                    null === get the current input value
359
     *                                    text === set a new input value
360
     *                                    </p>
361
     *
362
     * @return string|string[]|null
363
     */
364
    public function val($value = null)
365
    {
366
        return null;
367
    }
368
369
    /**
370
     * Retrieve an external iterator.
371
     *
372
     * @see  http://php.net/manual/en/iteratoraggregate.getiterator.php
373
     *
374
     * @return SimpleHtmlDomNodeInterface
375
     *                           <p>
376
     *                              An instance of an object implementing <b>Iterator</b> or
377
     *                              <b>Traversable</b>
378
     *                           </p>
379
     */
380
    public function getIterator(): SimpleHtmlDomNodeInterface
381
    {
382
        return new SimpleHtmlDomNodeBlank();
383
    }
384
385
    /**
386
     * Get dom node's inner xml.
387
     *
388
     * @param bool $multiDecodeNewHtmlEntity
389
     *
390
     * @return string
391
     */
392
    public function innerXml(bool $multiDecodeNewHtmlEntity = false): string
393
    {
394
        return '';
395
    }
396
}
397

src/voku/helper/SimpleXmlDomBlank.php 1 location

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