Completed
Branch TemplateNormalizations (ae42e4)
by Josh
33:16
created

NormalizeAttributeNames::normalizeAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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 DOMAttr;
11
use DOMElement;
12
13
class NormalizeAttributeNames extends AbstractNormalization
14
{
15
	/**
16
	* {@inheritdoc}
17
	*/
18
	protected $queries = ['//@*', '//xsl:attribute[not(contains(@name, "{"))]'];
19
20
	/**
21
	* {@inheritdoc}
22
	*/
23
	protected function normalizeAttribute(DOMAttr $attribute)
24
	{
25
		$attrName = $this->lowercase($attribute->localName);
26
		if ($attrName !== $attribute->localName)
27
		{
28
			$attribute->parentNode->setAttribute($attrName, $attribute->value);
29
			$attribute->parentNode->removeAttributeNode($attribute);
30
		}
31
	}
32
33
	/**
34
	* {@inheritdoc}
35
	*/
36
	protected function normalizeElement(DOMElement $element)
37
	{
38
		$element->setAttribute('name', $this->lowercase($element->getAttribute('name')));
39
	}
40
}