| Conditions | 20 |
| Paths | 13 |
| Total Lines | 57 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 21 | protected function convertDomNodeToArray($node) |
||
| 22 | { |
||
| 23 | $output = []; |
||
| 24 | |||
| 25 | switch ($node->nodeType) { |
||
| 26 | case XML_CDATA_SECTION_NODE: |
||
| 27 | case XML_TEXT_NODE: |
||
| 28 | $output = trim($node->textContent); |
||
| 29 | |||
| 30 | break; |
||
| 31 | case XML_ELEMENT_NODE: |
||
| 32 | for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) { |
||
| 33 | $child = $node->childNodes->item($i); |
||
| 34 | $v = $this->convertDomNodeToArray($child); |
||
| 35 | |||
| 36 | if (isset($child->tagName)) { |
||
| 37 | $t = $child->tagName; |
||
| 38 | if (!isset($output[$t])) { |
||
| 39 | $output[$t] = array(); |
||
| 40 | } |
||
| 41 | $output[$t][] = $v; |
||
| 42 | } elseif ($v || $v === '0') { |
||
| 43 | $output = (string)$v; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($node->attributes->length && !is_array($output)) { //Has attributes but isn't an array |
||
| 48 | $output = array('@content' => $output); //Change output into an array. |
||
| 49 | } |
||
| 50 | |||
| 51 | if (is_array($output)) { |
||
| 52 | if ($node->attributes->length) { |
||
| 53 | $a = array(); |
||
| 54 | foreach ($node->attributes as $attrName => $attrNode) { |
||
| 55 | $a[$attrName] = (string)$attrNode->value; |
||
| 56 | } |
||
| 57 | $output['@attributes'] = $a; |
||
| 58 | } |
||
| 59 | |||
| 60 | foreach ($output as $t => $v) { |
||
| 61 | // We are combining arrays for rdf:Bag, rdf:Alt, rdf:Seq |
||
| 62 | if (in_array($t, self::POSSIBLE_CONTAINERS)) { |
||
| 63 | if (!array_key_exists(self::RDF_LI, $v[0])) { |
||
| 64 | break; |
||
| 65 | } |
||
| 66 | |||
| 67 | $output = $v[0][self::RDF_LI]; |
||
| 68 | } elseif (is_array($v) && count($v) == 1 && $t != '@attributes') { |
||
| 69 | $output[$t] = $v[0]; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | break; |
||
| 75 | } |
||
| 76 | |||
| 77 | return $output; |
||
| 78 | } |
||
| 117 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.