Passed
Push — master ( 7bbd81...0263a7 )
by Josh
20:33 queued 09:30
created

ParentNodeWorkarounds::prepend()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
c 1
b 1
f 0
dl 0
loc 5
rs 10
cc 3
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
/**
4
* @package   s9e\SweetDOM
5
* @copyright Copyright (c) The s9e authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\SweetDOM\NodeTraits;
9
10
use DOMNode;
11
use function array_reverse, is_string;
12
13
trait ParentNodeWorkarounds
14
{
15
	// https://github.com/php/php-src/pull/11768 - fixed in ~8.1.23, ^8.2.10
16
	// https://github.com/php/php-src/pull/12308 - not sure why this mitigates this issue
17
	public function append(...$nodes): void
18
	{
19
		foreach ($nodes as $node)
20
		{
21
			$this->appendChild(is_string($node) ? $this->ownerDocument->createTextNode($node) : $node);
1 ignored issue
show
Bug introduced by
The method appendChild() does not exist on s9e\SweetDOM\NodeTraits\ParentNodeWorkarounds. Did you maybe mean append()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
			$this->/** @scrutinizer ignore-call */ 
22
          appendChild(is_string($node) ? $this->ownerDocument->createTextNode($node) : $node);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
		}
23
	}
24
25
	// https://github.com/php/php-src/pull/11768
26
	public function prepend(...$nodes): void
27
	{
28
		foreach (array_reverse($nodes) as $node)
29
		{
30
			$this->insertBefore(is_string($node) ? $this->ownerDocument->createTextNode($node) : $node, $this->firstChild);
1 ignored issue
show
Bug introduced by
It seems like insertBefore() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
			$this->/** @scrutinizer ignore-call */ 
31
          insertBefore(is_string($node) ? $this->ownerDocument->createTextNode($node) : $node, $this->firstChild);
Loading history...
31
		}
32
	}
33
}