Code Duplication    Length = 396-396 lines in 2 locations

src/voku/helper/SimpleHtmlDomBlank.php 1 location

@@ 12-407 (lines=396) @@
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
        return false;
61
    }
62
63
    /**
64
     * Return attribute value.
65
     *
66
     * @param string $name
67
     *
68
     * @return string
69
     */
70
    public function getAttribute(string $name): string
71
    {
72
        return '';
73
    }
74
75
    /**
76
     * Determine if an attribute exists on the element.
77
     *
78
     * @param string $name
79
     *
80
     * @return bool
81
     */
82
    public function hasAttribute(string $name): bool
83
    {
84
        return false;
85
    }
86
87
    /**
88
     * Get dom node's outer html.
89
     *
90
     * @param bool $multiDecodeNewHtmlEntity
91
     *
92
     * @return string
93
     */
94
    public function html(bool $multiDecodeNewHtmlEntity = false): string
95
    {
96
        return '';
97
    }
98
99
    /**
100
     * Get dom node's inner html.
101
     *
102
     * @param bool $multiDecodeNewHtmlEntity
103
     *
104
     * @return string
105
     */
106
    public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string
107
    {
108
        return '';
109
    }
110
111
    /**
112
     * Remove attribute.
113
     *
114
     * @param string $name <p>The name of the html-attribute.</p>
115
     *
116
     * @return SimpleHtmlDomInterface
117
     */
118
    public function removeAttribute(string $name): SimpleHtmlDomInterface
119
    {
120
        return $this;
121
    }
122
123
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
124
    {
125
        return new static();
126
    }
127
128
    protected function replaceNodeWithString(string $string): SimpleHtmlDomInterface
129
    {
130
        return new static();
131
    }
132
133
    protected function replaceTextWithString($string): SimpleHtmlDomInterface
134
    {
135
        return new static();
136
    }
137
138
    /**
139
     * Set attribute value.
140
     *
141
     * @param string      $name       <p>The name of the html-attribute.</p>
142
     * @param string|null $value      <p>Set to NULL or empty string, to remove the attribute.</p>
143
     * @param bool        $strict     </p>
144
     *                                $value must be NULL, to remove the attribute,
145
     *                                so that you can set an empty string as attribute-value e.g. autofocus=""
146
     *                                </p>
147
     *
148
     * @return SimpleHtmlDomInterface
149
     */
150
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface
151
    {
152
        return $this;
153
    }
154
155
    /**
156
     * Get dom node's plain text.
157
     *
158
     * @return string
159
     */
160
    public function text(): string
161
    {
162
        return '';
163
    }
164
165
    /**
166
     * Returns children of node.
167
     *
168
     * @param int $idx
169
     *
170
     * @return null
171
     */
172
    public function childNodes(int $idx = -1)
173
    {
174
        return null;
175
    }
176
177
    /**
178
     * Find nodes with a CSS selector.
179
     *
180
     * @param string $selector
181
     *
182
     * @return SimpleHtmlDomNodeInterface
183
     */
184
    public function findMulti(string $selector): SimpleHtmlDomNodeInterface
185
    {
186
        return new SimpleHtmlDomNodeBlank();
187
    }
188
189
    /**
190
     * Find nodes with a CSS selector or false, if no element is found.
191
     *
192
     * @param string $selector
193
     *
194
     * @return false
195
     */
196
    public function findMultiOrFalse(string $selector)
197
    {
198
        return false;
199
    }
200
201
    /**
202
     * Find one node with a CSS selector.
203
     *
204
     * @param string $selector
205
     *
206
     * @return SimpleHtmlDomInterface
207
     */
208
    public function findOne(string $selector): SimpleHtmlDomInterface
209
    {
210
        return new static();
211
    }
212
213
    /**
214
     * Find one node with a CSS selector or false, if no element is found.
215
     *
216
     * @param string $selector
217
     *
218
     * @return false
219
     */
220
    public function findOneOrFalse(string $selector)
221
    {
222
        return false;
223
    }
224
225
    /**
226
     * Returns the first child of node.
227
     *
228
     * @return null
229
     */
230
    public function firstChild()
231
    {
232
        return null;
233
    }
234
235
    /**
236
     * Return elements by ".class".
237
     *
238
     * @param string $class
239
     *
240
     * @return SimpleHtmlDomNodeInterface
241
     */
242
    public function getElementByClass(string $class): SimpleHtmlDomNodeInterface
243
    {
244
        return new SimpleHtmlDomNodeBlank();
245
    }
246
247
    /**
248
     * Return element by #id.
249
     *
250
     * @param string $id
251
     *
252
     * @return SimpleHtmlDomInterface
253
     */
254
    public function getElementById(string $id): SimpleHtmlDomInterface
255
    {
256
        return new static();
257
    }
258
259
    /**
260
     * Return element by tag name.
261
     *
262
     * @param string $name
263
     *
264
     * @return SimpleHtmlDomInterface
265
     */
266
    public function getElementByTagName(string $name): SimpleHtmlDomInterface
267
    {
268
        return new static();
269
    }
270
271
    /**
272
     * Returns elements by "#id".
273
     *
274
     * @param string   $id
275
     * @param int|null $idx
276
     *
277
     * @return SimpleHtmlDomNodeInterface
278
     */
279
    public function getElementsById(string $id, $idx = null)
280
    {
281
        return new SimpleHtmlDomNodeBlank();
282
    }
283
284
    /**
285
     * Returns elements by tag name.
286
     *
287
     * @param string   $name
288
     * @param int|null $idx
289
     *
290
     * @return SimpleHtmlDomNodeInterface
291
     */
292
    public function getElementsByTagName(string $name, $idx = null)
293
    {
294
        return new SimpleHtmlDomNodeBlank();
295
    }
296
297
    /**
298
     * Create a new "HtmlDomParser"-object from the current context.
299
     *
300
     * @return HtmlDomParser
301
     */
302
    public function getHtmlDomParser(): HtmlDomParser
303
    {
304
        return new HtmlDomParser($this);
305
    }
306
307
    /**
308
     * @return \DOMNode
309
     */
310
    public function getNode(): \DOMNode
311
    {
312
        return new \DOMNode();
313
    }
314
315
    /**
316
     * Nodes can get partially destroyed in which they're still an
317
     * actual DOM node (such as \DOMElement) but almost their entire
318
     * body is gone, including the `nodeType` attribute.
319
     *
320
     * @return bool true if node has been destroyed
321
     */
322
    public function isRemoved(): bool
323
    {
324
        return true;
325
    }
326
327
    /**
328
     * Returns the last child of node.
329
     *
330
     * @return null
331
     */
332
    public function lastChild()
333
    {
334
        return null;
335
    }
336
337
    /**
338
     * Returns the next sibling of node.
339
     *
340
     * @return null
341
     */
342
    public function nextSibling()
343
    {
344
        return null;
345
    }
346
347
    /**
348
     * Returns the parent of node.
349
     *
350
     * @return SimpleHtmlDomInterface
351
     */
352
    public function parentNode(): SimpleHtmlDomInterface
353
    {
354
        return new static();
355
    }
356
357
    /**
358
     * Returns the previous sibling of node.
359
     *
360
     * @return null
361
     */
362
    public function previousSibling()
363
    {
364
        return null;
365
    }
366
367
    /**
368
     * @param string|string[]|null $value <p>
369
     *                                    null === get the current input value
370
     *                                    text === set a new input value
371
     *                                    </p>
372
     *
373
     * @return string|string[]|null
374
     */
375
    public function val($value = null)
376
    {
377
        return null;
378
    }
379
380
    /**
381
     * Retrieve an external iterator.
382
     *
383
     * @see  http://php.net/manual/en/iteratoraggregate.getiterator.php
384
     *
385
     * @return SimpleHtmlDomNodeInterface
386
     *                           <p>
387
     *                              An instance of an object implementing <b>Iterator</b> or
388
     *                              <b>Traversable</b>
389
     *                           </p>
390
     */
391
    public function getIterator(): SimpleHtmlDomNodeInterface
392
    {
393
        return new SimpleHtmlDomNodeBlank();
394
    }
395
396
    /**
397
     * Get dom node's inner xml.
398
     *
399
     * @param bool $multiDecodeNewHtmlEntity
400
     *
401
     * @return string
402
     */
403
    public function innerXml(bool $multiDecodeNewHtmlEntity = false): string
404
    {
405
        return '';
406
    }
407
}
408

src/voku/helper/SimpleXmlDomBlank.php 1 location

@@ 12-407 (lines=396) @@
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
        return false;
61
    }
62
63
    /**
64
     * Return attribute value.
65
     *
66
     * @param string $name
67
     *
68
     * @return string
69
     */
70
    public function getAttribute(string $name): string
71
    {
72
        return '';
73
    }
74
75
    /**
76
     * Determine if an attribute exists on the element.
77
     *
78
     * @param string $name
79
     *
80
     * @return bool
81
     */
82
    public function hasAttribute(string $name): bool
83
    {
84
        return false;
85
    }
86
87
    /**
88
     * Get dom node's inner xml.
89
     *
90
     * @param bool $multiDecodeNewHtmlEntity
91
     *
92
     * @return string
93
     */
94
    public function innerXml(bool $multiDecodeNewHtmlEntity = false): string
95
    {
96
        return '';
97
    }
98
99
    /**
100
     * Remove attribute.
101
     *
102
     * @param string $name <p>The name of the html-attribute.</p>
103
     *
104
     * @return SimpleXmlDomInterface
105
     */
106
    public function removeAttribute(string $name): SimpleXmlDomInterface
107
    {
108
        return $this;
109
    }
110
111
    protected function replaceChildWithString(string $string): SimpleXmlDomInterface
112
    {
113
        return new static();
114
    }
115
116
    protected function replaceNodeWithString(string $string): SimpleXmlDomInterface
117
    {
118
        return new static();
119
    }
120
121
    protected function replaceTextWithString($string): SimpleXmlDomInterface
122
    {
123
        return new static();
124
    }
125
126
    /**
127
     * Set attribute value.
128
     *
129
     * @param string      $name       <p>The name of the html-attribute.</p>
130
     * @param string|null $value      <p>Set to NULL or empty string, to remove the attribute.</p>
131
     * @param bool        $strict     </p>
132
     *                                $value must be NULL, to remove the attribute,
133
     *                                so that you can set an empty string as attribute-value e.g. autofocus=""
134
     *                                </p>
135
     *
136
     * @return SimpleXmlDomInterface
137
     */
138
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleXmlDomInterface
139
    {
140
        return $this;
141
    }
142
143
    /**
144
     * Get dom node's plain text.
145
     *
146
     * @return string
147
     */
148
    public function text(): string
149
    {
150
        return '';
151
    }
152
153
    /**
154
     * Get dom node's outer html.
155
     *
156
     * @param bool $multiDecodeNewHtmlEntity
157
     *
158
     * @return string
159
     */
160
    public function xml(bool $multiDecodeNewHtmlEntity = false): string
161
    {
162
        return '';
163
    }
164
165
    /**
166
     * Returns children of node.
167
     *
168
     * @param int $idx
169
     *
170
     * @return null
171
     */
172
    public function childNodes(int $idx = -1)
173
    {
174
        return null;
175
    }
176
177
    /**
178
     * Find nodes with a CSS selector.
179
     *
180
     * @param string $selector
181
     *
182
     * @return SimpleXmlDomNodeInterface
183
     */
184
    public function findMulti(string $selector): SimpleXmlDomNodeInterface
185
    {
186
        return new SimpleXmlDomNodeBlank();
187
    }
188
189
    /**
190
     * Find nodes with a CSS selector or false, if no element is found.
191
     *
192
     * @param string $selector
193
     *
194
     * @return false
195
     */
196
    public function findMultiOrFalse(string $selector)
197
    {
198
        return false;
199
    }
200
201
    /**
202
     * Find one node with a CSS selector.
203
     *
204
     * @param string $selector
205
     *
206
     * @return SimpleXmlDomInterface
207
     */
208
    public function findOne(string $selector): SimpleXmlDomInterface
209
    {
210
        return new static();
211
    }
212
213
    /**
214
     * Find one node with a CSS selector or false, if no element is found.
215
     *
216
     * @param string $selector
217
     *
218
     * @return false
219
     */
220
    public function findOneOrFalse(string $selector)
221
    {
222
        return false;
223
    }
224
225
    /**
226
     * Returns the first child of node.
227
     *
228
     * @return null
229
     */
230
    public function firstChild()
231
    {
232
        return null;
233
    }
234
235
    /**
236
     * Return elements by ".class".
237
     *
238
     * @param string $class
239
     *
240
     * @return SimpleXmlDomNodeInterface
241
     */
242
    public function getElementByClass(string $class): SimpleXmlDomNodeInterface
243
    {
244
        return new SimpleXmlDomNodeBlank();
245
    }
246
247
    /**
248
     * Return element by #id.
249
     *
250
     * @param string $id
251
     *
252
     * @return SimpleXmlDomInterface
253
     */
254
    public function getElementById(string $id): SimpleXmlDomInterface
255
    {
256
        return new static();
257
    }
258
259
    /**
260
     * Return element by tag name.
261
     *
262
     * @param string $name
263
     *
264
     * @return SimpleXmlDomInterface
265
     */
266
    public function getElementByTagName(string $name): SimpleXmlDomInterface
267
    {
268
        return new static();
269
    }
270
271
    /**
272
     * Returns elements by "#id".
273
     *
274
     * @param string   $id
275
     * @param int|null $idx
276
     *
277
     * @return SimpleXmlDomNodeInterface
278
     */
279
    public function getElementsById(string $id, $idx = null)
280
    {
281
        return new SimpleXmlDomNodeBlank();
282
    }
283
284
    /**
285
     * Returns elements by tag name.
286
     *
287
     * @param string   $name
288
     * @param int|null $idx
289
     *
290
     * @return SimpleXmlDomNodeInterface
291
     */
292
    public function getElementsByTagName(string $name, $idx = null)
293
    {
294
        return new SimpleXmlDomNodeBlank();
295
    }
296
297
    /**
298
     * @return \DOMNode
299
     */
300
    public function getNode(): \DOMNode
301
    {
302
        return new \DOMNode();
303
    }
304
305
    /**
306
     * Create a new "XmlDomParser"-object from the current context.
307
     *
308
     * @return XmlDomParser
309
     */
310
    public function getXmlDomParser(): XmlDomParser
311
    {
312
        return new XmlDomParser($this);
313
    }
314
315
    /**
316
     * Get dom node's inner html.
317
     *
318
     * @param bool $multiDecodeNewHtmlEntity
319
     *
320
     * @return string
321
     */
322
    public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string
323
    {
324
        return '';
325
    }
326
327
    /**
328
     * Nodes can get partially destroyed in which they're still an
329
     * actual DOM node (such as \DOMElement) but almost their entire
330
     * body is gone, including the `nodeType` attribute.
331
     *
332
     * @return bool true if node has been destroyed
333
     */
334
    public function isRemoved(): bool
335
    {
336
        return true;
337
    }
338
339
    /**
340
     * Returns the last child of node.
341
     *
342
     * @return null
343
     */
344
    public function lastChild()
345
    {
346
        return null;
347
    }
348
349
    /**
350
     * Returns the next sibling of node.
351
     *
352
     * @return null
353
     */
354
    public function nextSibling()
355
    {
356
        return null;
357
    }
358
359
    /**
360
     * Returns the parent of node.
361
     *
362
     * @return SimpleXmlDomInterface
363
     */
364
    public function parentNode(): SimpleXmlDomInterface
365
    {
366
        return new static();
367
    }
368
369
    /**
370
     * Returns the previous sibling of node.
371
     *
372
     * @return null
373
     */
374
    public function previousSibling()
375
    {
376
        return null;
377
    }
378
379
    /**
380
     * @param string|string[]|null $value <p>
381
     *                                    null === get the current input value
382
     *                                    text === set a new input value
383
     *                                    </p>
384
     *
385
     * @return string|string[]|null
386
     */
387
    public function val($value = null)
388
    {
389
        return null;
390
    }
391
392
    /**
393
     * Retrieve an external iterator.
394
     *
395
     * @see  http://php.net/manual/en/iteratoraggregate.getiterator.php
396
     *
397
     * @return SimpleXmlDomNodeInterface
398
     *                           <p>
399
     *                              An instance of an object implementing <b>Iterator</b> or
400
     *                              <b>Traversable</b>
401
     *                           </p>
402
     */
403
    public function getIterator(): SimpleXmlDomNodeInterface
404
    {
405
        return new SimpleXmlDomNodeBlank();
406
    }
407
}
408