| Total Complexity | 23 |
| Total Lines | 131 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | abstract class AbstractNormalization |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * XSL namespace |
||
| 22 | */ |
||
| 23 | const XMLNS_XSL = 'http://www.w3.org/1999/XSL/Transform'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var Document Document that holds the template being normalized |
||
| 27 | */ |
||
| 28 | protected Document $ownerDocument; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string[] XPath queries used to retrieve nodes of interest |
||
| 32 | */ |
||
| 33 | protected array $queries = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Apply this normalization rule to given template |
||
| 37 | * |
||
| 38 | * @param Element $template <xsl:template/> node |
||
| 39 | */ |
||
| 40 | public function normalize(Element $template): void |
||
| 41 | { |
||
| 42 | $this->ownerDocument = $template->ownerDocument; |
||
| 43 | foreach ($this->getNodes() as $node) |
||
| 44 | { |
||
| 45 | // Ignore nodes that have been removed from the document |
||
| 46 | if ($node->parentNode) |
||
| 47 | { |
||
| 48 | $this->normalizeNode($node); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | $this->reset(); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Create an xsl:text element or a text node in current template |
||
| 56 | */ |
||
| 57 | protected function createPolymorphicText(string $textContent): Element|Text |
||
| 58 | { |
||
| 59 | return (trim($textContent) === '') |
||
| 60 | ? $this->ownerDocument->nodeCreator->createXslText($textContent) |
||
| 61 | : $this->ownerDocument->createTextNode($textContent); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Query and return a list of nodes of interest |
||
| 66 | * |
||
| 67 | * @return DOMNode[] |
||
| 68 | */ |
||
| 69 | protected function getNodes(): array |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Test whether given node is an XSL element |
||
| 78 | * |
||
| 79 | * @param DOMNode $node |
||
| 80 | * @param string $localName |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | protected function isXsl(DOMNode $node, $localName = null): bool |
||
| 84 | { |
||
| 85 | return ($node->namespaceURI === self::XMLNS_XSL && (!isset($localName) || $localName === $node->localName)); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Make an ASCII string lowercase |
||
| 90 | * |
||
| 91 | * @param string $str Original string |
||
| 92 | * @return string Lowercased string |
||
| 93 | */ |
||
| 94 | protected function lowercase($str) |
||
| 95 | { |
||
| 96 | return strtr($str, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); |
||
| 97 | } |
||
| 98 | |||
| 99 | protected function normalizeAttribute(Attr $attribute): void |
||
|
1 ignored issue
–
show
|
|||
| 100 | { |
||
| 101 | } |
||
| 102 | |||
| 103 | protected function normalizeCdataSection(CdataSection $comment): void |
||
| 104 | { |
||
| 105 | } |
||
| 106 | |||
| 107 | protected function normalizeComment(Comment $comment): void |
||
|
1 ignored issue
–
show
|
|||
| 108 | { |
||
| 109 | } |
||
| 110 | |||
| 111 | protected function normalizeElement(Element $element): void |
||
|
1 ignored issue
–
show
|
|||
| 112 | { |
||
| 113 | } |
||
| 114 | |||
| 115 | protected function normalizeNode(DOMNode $node): void |
||
| 116 | { |
||
| 117 | if ($node instanceof Element) |
||
| 118 | { |
||
| 119 | $this->normalizeElement($node); |
||
| 120 | } |
||
| 121 | elseif ($node instanceof Attr) |
||
| 122 | { |
||
| 123 | $this->normalizeAttribute($node); |
||
| 124 | } |
||
| 125 | elseif ($node instanceof Text) |
||
| 126 | { |
||
| 127 | $this->normalizeText($node); |
||
| 128 | } |
||
| 129 | elseif ($node instanceof Comment) |
||
| 130 | { |
||
| 131 | $this->normalizeComment($node); |
||
| 132 | } |
||
| 133 | elseif ($node instanceof CdataSection) |
||
| 134 | { |
||
| 135 | $this->normalizeCdataSection($node); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | protected function normalizeText(Text $node): void |
||
| 140 | { |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Reset this instance's properties after usage |
||
| 145 | */ |
||
| 146 | protected function reset(): void |
||
| 149 | } |
||
| 150 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.