| Conditions | 11 |
| Paths | 10 |
| Total Lines | 43 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 35 | public static function canonicalizeData( |
||
| 36 | DOMElement $element, |
||
| 37 | string $c14nMethod, |
||
| 38 | ?array $xpaths = null, |
||
| 39 | ?array $prefixes = null, |
||
| 40 | ): string { |
||
| 41 | $withComments = match ($c14nMethod) { |
||
| 42 | C::C14N_EXCLUSIVE_WITH_COMMENTS, C::C14N_INCLUSIVE_WITH_COMMENTS => true, |
||
| 43 | default => false, |
||
| 44 | }; |
||
| 45 | $exclusive = match ($c14nMethod) { |
||
| 46 | C::C14N_EXCLUSIVE_WITH_COMMENTS, C::C14N_EXCLUSIVE_WITHOUT_COMMENTS => true, |
||
| 47 | default => false, |
||
| 48 | }; |
||
| 49 | |||
| 50 | if ( |
||
| 51 | is_null($xpaths) |
||
| 52 | && ($element->ownerDocument !== null) |
||
| 53 | && ($element->ownerDocument->documentElement !== null) |
||
| 54 | && $element->isSameNode($element->ownerDocument->documentElement) |
||
| 55 | ) { |
||
| 56 | // check for any PI or comments as they would have been excluded |
||
| 57 | $current = $element; |
||
| 58 | for ($refNode = $current->previousSibling; $refNode !== null; $current = $refNode) { |
||
|
|
|||
| 59 | if ( |
||
| 60 | (($refNode->nodeType === XML_COMMENT_NODE) && $withComments) |
||
| 61 | || $refNode->nodeType === XML_PI_NODE |
||
| 62 | ) { |
||
| 63 | break; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($refNode === null) { |
||
| 68 | $element = $element->ownerDocument; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | $ret = $element->C14N($exclusive, $withComments, $xpaths, $prefixes); |
||
| 73 | if ($ret === false) { |
||
| 74 | // GHSA-h25p-2wxc-6584 |
||
| 75 | throw new CanonicalizationFailedException(); |
||
| 76 | } |
||
| 77 | return $ret; |
||
| 78 | } |
||
| 132 |