Completed
Push — master ( f7b88b...3755ed )
by Josh
14:40
created

MergeConsecutiveCopyOf::mergeCopyOfSiblings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
9
10
use DOMElement;
11
12
class MergeConsecutiveCopyOf extends AbstractNormalization
13
{
14
	/**
15
	* {@inheritdoc}
16
	*/
17
	protected $queries = ['//xsl:copy-of'];
18
19
	/**
20
	* {@inheritdoc}
21
	*/
22 5
	protected function normalizeElement(DOMElement $element)
23
	{
24 5
		while ($this->nextSiblingIsCopyOf($element))
25
		{
26 3
			$element->setAttribute('select', $element->getAttribute('select') . '|' . $element->nextSibling->getAttribute('select'));
27 3
			$element->parentNode->removeChild($element->nextSibling);
28
		}
29 5
	}
30
31
	/**
32
	* Test whether the next sibling to given element is an xsl:copy-of element
33
	*
34
	* @param  DOMElement $element Context node
35
	* @return bool
36
	*/
37 5
	protected function nextSiblingIsCopyOf(DOMElement $element)
38
	{
39 5
		return ($element->nextSibling && $this->isXsl($element->nextSibling, 'copy-of'));
40
	}
41
}