Completed
Push — master ( 236b50...7a7214 )
by Lars
02:07
created

SimpleHtmlDomBlank::innerHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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
        return false;
61
    }
62
63
    /**
64
     * Return attribute value.
65
     *
66
     * @param string $name
67
     *
68
     * @return string
69
     */
70 2
    public function getAttribute(string $name): string
71
    {
72 2
        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 1
    public function html(bool $multiDecodeNewHtmlEntity = false): string
95
    {
96 1
        return '';
97
    }
98
99
    /**
100
     * Get dom node's inner html.
101
     *
102
     * @param bool $multiDecodeNewHtmlEntity
103
     *
104
     * @return string
105
     */
106 1
    public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string
107
    {
108 1
        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;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDo...erface::removeAttribute of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
121
    }
122
123 2
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
124
    {
125 2
        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 1
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface
151
    {
152 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDomInterface::setAttribute of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
153
    }
154
155
    /**
156
     * Get dom node's plain text.
157
     *
158
     * @return string
159
     */
160 3
    public function text(): string
161
    {
162 3
        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();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new static(); (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDomInterface::findOne of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
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();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new static(); (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDomInterface::getElementById of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
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();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new static(); (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDo...ce::getElementByTagName of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
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();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new static(); (voku\helper\SimpleHtmlDomBlank) is incompatible with the return type declared by the interface voku\helper\SimpleHtmlDomInterface::parentNode of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
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 1
    public function getIterator(): SimpleHtmlDomNodeInterface
392
    {
393 1
        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