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

NormalizeAttributeNames::normalize()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 1
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A NormalizeAttributeNames::normalizeAttribute() 0 9 2
A NormalizeAttributeNames::normalizeElement() 0 4 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
}