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

DisallowAttributeSets   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 10 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\TemplateChecks;
9
10
use DOMElement;
11
use DOMXPath;
12
use s9e\TextFormatter\Configurator\Exceptions\UnsafeTemplateException;
13
use s9e\TextFormatter\Configurator\Items\Tag;
14
use s9e\TextFormatter\Configurator\TemplateCheck;
15
16
class DisallowAttributeSets extends TemplateCheck
17
{
18
	/**
19
	* Test whether the template contains an <xsl:attribute-set/>
20
	*
21
	* Templates are checked outside of their stylesheet, which means we don't have access to the
22
	* <xsl:attribute-set/> declarations and we can't easily test them. Attribute sets are fairly
23
	* uncommon and there's little incentive to use them in small stylesheets
24
	*
25
	* @param  DOMElement $template <xsl:template/> node
26
	* @param  Tag        $tag      Tag this template belongs to
27
	* @return void
28
	*/
29 1
	public function check(DOMElement $template, Tag $tag)
30
	{
31 1
		$xpath = new DOMXPath($template->ownerDocument);
32 1
		$nodes = $xpath->query('//@use-attribute-sets');
33
34 1
		if ($nodes->length)
35
		{
36 1
			throw new UnsafeTemplateException('Cannot assess the safety of attribute sets', $nodes->item(0));
37
		}
38
	}
39
}