Passed
Push — master ( 2eb814...039015 )
by Josh
06:20
created

DisallowUnsupportedXSL   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
eloc 15
c 1
b 0
f 1
dl 0
loc 51
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A checkXslWhenElement() 0 5 2
A checkXslVariableElement() 0 5 2
A checkXslValueOfElement() 0 5 2
A checkXslIfElement() 0 5 2
A checkXslCopyOfElement() 0 5 2
A checkXslApplyTemplatesElement() 0 5 2
1
<?php declare(strict_types=1);
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2020 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 RuntimeException;
12
13
class DisallowUnsupportedXSL extends AbstractXSLSupportCheck
14
{
15
	protected $supportedElements = ['apply-templates', 'attribute', 'choose', 'comment', 'copy-of', 'element', 'for-each', 'if', 'number', 'otherwise', 'processing-instruction', 'sort', 'text', 'value-of', 'variable', 'when'];
16
17
	protected $supportedFunctions = ['boolean', 'ceiling', 'concat', 'contains', 'count', 'current', 'document', 'element-available', 'false', 'floor', 'format-number', 'function-available', 'generate-id', 'id', 'key', 'lang', 'last', 'local-name', 'name', 'namespace-uri', 'normalize-space', 'not', 'number', 'position', 'round', 'starts-with', 'string', 'string-length', 'substring', 'substring-after', 'substring-before', 'sum', 'system-property', 'translate', 'true', 'unparsed-entity-uri'];
18
19 1
	protected function checkXslApplyTemplatesElement(DOMElement $applyTemplates): void
20
	{
21 1
		if ($applyTemplates->hasAttribute('mode'))
22
		{
23 1
			throw new RuntimeException('xsl:apply-templates elements do not support the mode attribute');
24
		}
25
	}
26
27 1
	protected function checkXslCopyOfElement(DOMElement $copyOf): void
28
	{
29 1
		if (!$copyOf->hasAttribute('select'))
30
		{
31 1
			throw new RuntimeException('xsl:copy-of elements require a select attribute');
32
		}
33
	}
34
35 1
	protected function checkXslIfElement(DOMElement $if): void
36
	{
37 1
		if (!$if->hasAttribute('test'))
38
		{
39 1
			throw new RuntimeException('xsl:if elements require a test attribute');
40
		}
41
	}
42
43 2
	protected function checkXslValueOfElement(DOMElement $valueOf): void
44
	{
45 2
		if (!$valueOf->hasAttribute('select'))
46
		{
47 1
			throw new RuntimeException('xsl:value-of elements require a select attribute');
48
		}
49
	}
50
51 1
	protected function checkXslVariableElement(DOMElement $variable): void
52
	{
53 1
		if (!$variable->hasAttribute('name'))
54
		{
55 1
			throw new RuntimeException('xsl:variable elements require a name attribute');
56
		}
57
	}
58
59 1
	protected function checkXslWhenElement(DOMElement $when): void
60
	{
61 1
		if (!$when->hasAttribute('test'))
62
		{
63 1
			throw new RuntimeException('xsl:when elements require a test attribute');
64
		}
65
	}
66
}