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