Code Duplication    Length = 407-407 lines in 2 locations

src/voku/helper/SimpleHtmlDomBlank.php 1 location

@@ 12-418 (lines=407) @@
9
 *
10
 * {@inheritdoc}
11
 */
12
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
    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 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
    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 outer html.
90
     *
91
     * @param bool $multiDecodeNewHtmlEntity
92
     *
93
     * @return string
94
     */
95
    public function html(bool $multiDecodeNewHtmlEntity = false): string
96
    {
97
        return '';
98
    }
99
100
    /**
101
     * Get dom node's inner html.
102
     *
103
     * @param bool $multiDecodeNewHtmlEntity
104
     *
105
     * @return string
106
     */
107
    public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string
108
    {
109
        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
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
125
    {
126
        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
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface
152
    {
153
        return $this;
154
    }
155
156
    /**
157
     * Get dom node's plain text.
158
     *
159
     * @return string
160
     */
161
    public function text(): 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 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
    public function getIterator(): SimpleHtmlDomNodeInterface
403
    {
404
        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

src/voku/helper/SimpleXmlDomBlank.php 1 location

@@ 12-418 (lines=407) @@
9
 *
10
 * {@inheritdoc}
11
 */
12
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