Completed
Push — master ( e70e95...72eb9f )
by Josh
04:30
created

DisallowDynamicAttributeNames::check()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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\TemplateChecks;
9
10
use DOMElement;
11
use s9e\TextFormatter\Configurator\Exceptions\UnsafeTemplateException;
12
use s9e\TextFormatter\Configurator\Items\Tag;
13
use s9e\TextFormatter\Configurator\TemplateCheck;
14
15
class DisallowDynamicAttributeNames extends TemplateCheck
16
{
17
	/**
18
	* Test for the presence of an <xsl:attribute/> node using a dynamic name
19
	*
20
	* @param  DOMElement $template <xsl:template/> node
21
	* @param  Tag        $tag      Tag this template belongs to
22
	* @return void
23
	*/
24 1
	public function check(DOMElement $template, Tag $tag)
25
	{
26 1
		$nodes = $template->getElementsByTagNameNS(self::XMLNS_XSL, 'attribute');
27 1
		foreach ($nodes as $node)
28
		{
29 1
			if (strpos($node->getAttribute('name'), '{') !== false)
30
			{
31 1
				throw new UnsafeTemplateException('Dynamic <xsl:attribute/> names are disallowed', $node);
32
			}
33
		}
34
	}
35
}