| Conditions | 12 |
| Paths | 20 |
| Total Lines | 58 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 85 | public static function processTransforms( |
||
| 86 | Transforms $transforms, |
||
| 87 | DOMElement $data, |
||
| 88 | bool $includeCommentNodes = false |
||
| 89 | ): string { |
||
| 90 | $canonicalMethod = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS; |
||
| 91 | $arXPath = null; |
||
| 92 | $prefixList = null; |
||
| 93 | foreach ($transforms as $transform) { |
||
| 94 | /** @var Transform $transform */ |
||
| 95 | $algorithm = $transform->getAlgorithm(); |
||
| 96 | switch ($algorithm) { |
||
| 97 | case C::C14N_EXCLUSIVE_WITHOUT_COMMENTS: |
||
| 98 | case C::C14N_EXCLUSIVE_WITH_COMMENTS: |
||
| 99 | if (!$includeCommentNodes) { |
||
| 100 | // remove comment nodes by forcing it to use a canonicalization without comments |
||
| 101 | $canonicalMethod = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS; |
||
| 102 | } else { |
||
| 103 | $canonicalMethod = $algorithm; |
||
| 104 | } |
||
| 105 | |||
| 106 | $inclusiveNamespaces = $transform->getInclusiveNamespaces(); |
||
| 107 | if ($inclusiveNamespaces !== null) { |
||
| 108 | $prefixes = $inclusiveNamespaces->getPrefixes(); |
||
| 109 | if (count($prefixes) > 0) { |
||
| 110 | $prefixList = $prefixes; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | break; |
||
| 114 | case C::C14N_INCLUSIVE_WITHOUT_COMMENTS: |
||
| 115 | case C::C14N_INCLUSIVE_WITH_COMMENTS: |
||
| 116 | if (!$includeCommentNodes) { |
||
| 117 | // remove comment nodes by forcing it to use a canonicalization without comments |
||
| 118 | $canonicalMethod = C::C14N_INCLUSIVE_WITHOUT_COMMENTS; |
||
| 119 | } else { |
||
| 120 | $canonicalMethod = $algorithm; |
||
| 121 | } |
||
| 122 | |||
| 123 | break; |
||
| 124 | case C::XPATH_URI: |
||
| 125 | $xpath = $transform->getXPath(); |
||
| 126 | if ($xpath !== null) { |
||
| 127 | $arXPath = []; |
||
| 128 | $arXPath['query'] = '(.//. | .//@* | .//namespace::*)[' . $xpath->getExpression() . ']'; |
||
| 129 | $arXpath['namespaces'] = $xpath->getNamespaces(); |
||
| 130 | // TODO: review if $nsnode->localName is equivalent to the keys in getNamespaces() |
||
| 131 | // $nslist = $xp->query('./namespace::*', $node); |
||
| 132 | // foreach ($nslist as $nsnode) { |
||
| 133 | // if ($nsnode->localName != "xml") { |
||
| 134 | // $arXPath['namespaces'][$nsnode->localName] = $nsnode->nodeValue; |
||
| 135 | // } |
||
| 136 | // } |
||
| 137 | } |
||
| 138 | break; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | return self::canonicalizeData($data, $canonicalMethod, $arXPath, $prefixList); |
||
| 143 | } |
||
| 145 |