Completed
Push — master ( d36330...3c9b9d )
by Lars
01:55
created

SimpleHtmlDomBlank::previousSibling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace voku\helper;
6
7
/** @noinspection PhpHierarchyChecksInspection */
8 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...
9
{
10
    /**
11
     * @param string $name
12
     * @param array  $arguments
13
     *
14
     * @throws \BadMethodCallException
15
     *
16
     * @return SimpleHtmlDomInterface|string|null
17
     */
18 1
    public function __call($name, $arguments)
19
    {
20 1
        $name = \strtolower($name);
21
22 1
        if (isset(self::$functionAliases[$name])) {
23 1
            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 2
    public function getAttribute(string $name): string
60
    {
61 2
        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 1
    public function html(bool $multiDecodeNewHtmlEntity = false): string
84
    {
85 1
        return '';
86
    }
87
88
    /**
89
     * Get dom node's inner html.
90
     *
91
     * @param bool $multiDecodeNewHtmlEntity
92
     *
93
     * @return string
94
     */
95 1
    public function innerHtml(bool $multiDecodeNewHtmlEntity = false): string
96
    {
97 1
        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;
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...
110
    }
111
112 2
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
113
    {
114 2
        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 1
    public function setAttribute(string $name, $value = null, bool $strict = false): SimpleHtmlDomInterface
140
    {
141 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...
142
    }
143
144
    /**
145
     * Get dom node's plain text.
146
     *
147
     * @return string
148
     */
149 3
    public function text(): string
150
    {
151 3
        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 one node with a CSS selector.
180
     *
181
     * @param string $selector
182
     *
183
     * @return SimpleHtmlDomInterface
184
     */
185
    public function findOne(string $selector): SimpleHtmlDomInterface
186
    {
187
        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...
188
    }
189
190
    /**
191
     * Returns the first child of node.
192
     *
193
     * @return null
194
     */
195
    public function firstChild()
196
    {
197
        return null;
198
    }
199
200
    /**
201
     * Return elements by .class.
202
     *
203
     * @param string $class
204
     *
205
     * @return SimpleHtmlDomNodeInterface
206
     */
207
    public function getElementByClass(string $class): SimpleHtmlDomNodeInterface
208
    {
209
        return new SimpleHtmlDomNodeBlank();
210
    }
211
212
    /**
213
     * Return element by #id.
214
     *
215
     * @param string $id
216
     *
217
     * @return SimpleHtmlDomInterface
218
     */
219
    public function getElementById(string $id): SimpleHtmlDomInterface
220
    {
221
        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...
222
    }
223
224
    /**
225
     * Return element by tag name.
226
     *
227
     * @param string $name
228
     *
229
     * @return SimpleHtmlDomInterface
230
     */
231
    public function getElementByTagName(string $name): SimpleHtmlDomInterface
232
    {
233
        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...
234
    }
235
236
    /**
237
     * Returns elements by #id.
238
     *
239
     * @param string   $id
240
     * @param int|null $idx
241
     *
242
     * @return SimpleHtmlDomNodeInterface
243
     */
244
    public function getElementsById(string $id, $idx = null)
245
    {
246
        return new SimpleHtmlDomNodeBlank();
247
    }
248
249
    /**
250
     * Returns elements by tag name.
251
     *
252
     * @param string   $name
253
     * @param int|null $idx
254
     *
255
     * @return SimpleHtmlDomNodeInterface
256
     */
257
    public function getElementsByTagName(string $name, $idx = null)
258
    {
259
        return new SimpleHtmlDomNodeBlank();
260
    }
261
262
    /**
263
     * Create a new "HtmlDomParser"-object from the current context.
264
     *
265
     * @return HtmlDomParser
266
     */
267
    public function getHtmlDomParser(): HtmlDomParser
268
    {
269
        return new HtmlDomParser($this);
270
    }
271
272
    /**
273
     * @return \DOMNode
274
     */
275
    public function getNode(): \DOMNode
276
    {
277
        return new \DOMNode();
278
    }
279
280
    /**
281
     * Nodes can get partially destroyed in which they're still an
282
     * actual DOM node (such as \DOMElement) but almost their entire
283
     * body is gone, including the `nodeType` attribute.
284
     *
285
     * @return bool true if node has been destroyed
286
     */
287
    public function isRemoved(): bool
288
    {
289
        return true;
290
    }
291
292
    /**
293
     * Returns the last child of node.
294
     *
295
     * @return null
296
     */
297
    public function lastChild()
298
    {
299
        return null;
300
    }
301
302
    /**
303
     * Returns the next sibling of node.
304
     *
305
     * @return null
306
     */
307
    public function nextSibling()
308
    {
309
        return null;
310
    }
311
312
    /**
313
     * Returns the parent of node.
314
     *
315
     * @return SimpleHtmlDomInterface
316
     */
317
    public function parentNode(): SimpleHtmlDomInterface
318
    {
319
        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...
320
    }
321
322
    /**
323
     * Returns the previous sibling of node.
324
     *
325
     * @return null
326
     */
327
    public function previousSibling()
328
    {
329
        return null;
330
    }
331
332
    /**
333
     * @param string|string[]|null $value <p>
334
     *                                    null === get the current input value
335
     *                                    text === set a new input value
336
     *                                    </p>
337
     *
338
     * @return string|string[]|null
339
     */
340
    public function val($value = null)
341
    {
342
        return null;
343
    }
344
345
    /**
346
     * Retrieve an external iterator.
347
     *
348
     * @see  http://php.net/manual/en/iteratoraggregate.getiterator.php
349
     *
350
     * @return SimpleHtmlDomNodeInterface
351
     *                           <p>
352
     *                              An instance of an object implementing <b>Iterator</b> or
353
     *                              <b>Traversable</b>
354
     *                           </p>
355
     */
356 1
    public function getIterator(): SimpleHtmlDomNodeInterface
357
    {
358 1
        return new SimpleHtmlDomNodeBlank();
359
    }
360
361
    /**
362
     * Get dom node's inner xml.
363
     *
364
     * @param bool $multiDecodeNewHtmlEntity
365
     *
366
     * @return string
367
     */
368
    public function innerXml(bool $multiDecodeNewHtmlEntity = false): string
0 ignored issues
show
Unused Code introduced by
The parameter $multiDecodeNewHtmlEntity is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
369
    {
370
        return '';
371
    }
372
}
373