Passed
Push — master ( f7dddb...4ef14d )
by Josh
04:03
created

DeoptimizeIf::normalizeElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2019 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
/**
13
* De-optimize xsl:if elements so that xsl:choose dead branch elimination can apply to them
14
*/
15
class DeoptimizeIf extends AbstractNormalization
16
{
17
	/**
18
	* {@inheritdoc}
19
	*/
20
	protected $queries = ['//xsl:if[@test]'];
21
22
	/**
23
	* {@inheritdoc}
24
	*/
25 1
	protected function normalizeElement(DOMElement $if)
26
	{
27 1
		$choose = $this->createElement('xsl:choose');
28 1
		$when   = $choose->appendChild($this->createElement('xsl:when'));
29 1
		$when->setAttribute('test', $if->getAttribute('test'));
30 1
		while ($if->firstChild)
31
		{
32 1
			$when->appendChild($if->firstChild);
33
		}
34 1
		$if->parentNode->replaceChild($choose, $if);
35
	}
36
}