ParentNodeWorkarounds   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
eloc 4
c 1
b 1
f 0
dl 0
loc 18
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A append() 0 5 3
A prepend() 0 5 3
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);
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);
31
		}
32
	}
33
}