| Conditions | 10 |
| Paths | 120 |
| Total Lines | 63 |
| 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 |
||
| 83 | public function add(Node $node) |
||
| 84 | { |
||
| 85 | $wrapperElement = null; |
||
| 86 | |||
| 87 | if ($node->hasOutstandingReferences()) { |
||
| 88 | $schemaDefinition = $node->outstandingReferences['schema_definition']; |
||
| 89 | $namespace = $node->outstandingReferences['namespace']; |
||
| 90 | |||
| 91 | $this->setSchemaDefinition($schemaDefinition); |
||
|
|
|||
| 92 | $this->setNamespace($namespace); |
||
| 93 | } |
||
| 94 | |||
| 95 | if (isset($node->schemaDefinition) && $node->globalSchemaLocation) { |
||
| 96 | $this->setSchemaDefinition( |
||
| 97 | $node->getSchemaLocation() |
||
| 98 | ); |
||
| 99 | |||
| 100 | $this->setNamespace($node); |
||
| 101 | } |
||
| 102 | |||
| 103 | $nodeElement = $this->document->createElement($node->getNodeName()); |
||
| 104 | $this->setAttr($nodeElement, $node->getAttr()); |
||
| 105 | |||
| 106 | foreach ($node->element->childNodes as $child) { |
||
| 107 | $nodeElement->appendChild( |
||
| 108 | $this->document->importNode($child, true) |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($wrapperName = $node->getWrapperNodeName()) { |
||
| 113 | $wrapperElement = $this->getDirectChildElementByName( |
||
| 114 | $this->element->childNodes, |
||
| 115 | $wrapperName |
||
| 116 | ); |
||
| 117 | |||
| 118 | if (!$wrapperElement) { |
||
| 119 | $wrapperElement = $this->document->createElement($wrapperName); |
||
| 120 | $this->element->appendChild($wrapperElement); |
||
| 121 | } |
||
| 122 | |||
| 123 | $this->setAttr($wrapperElement, $node->getAttr('wrapper')); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($parentName = $node->getParentNodeName()) { |
||
| 127 | $currentElement = ($wrapperElement) ? $wrapperElement : $this->element; |
||
| 128 | |||
| 129 | $parentNode = $this->getDirectChildElementByName( |
||
| 130 | $currentElement->childNodes, |
||
| 131 | $parentName |
||
| 132 | ); |
||
| 133 | |||
| 134 | if (!$parentNode) { |
||
| 135 | $parentElement = $this->document->createElement($parentName); |
||
| 136 | $currentElement->appendChild($parentElement); |
||
| 137 | $parentElement->appendChild($nodeElement); |
||
| 138 | $this->setAttr($parentElement, $node->getAttr('parent')); |
||
| 139 | } else { |
||
| 140 | $parentNode->appendChild($nodeElement); |
||
| 141 | } |
||
| 142 | } else { |
||
| 143 | $this->element->appendChild($nodeElement); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 311 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.