| Conditions | 22 |
| Paths | 401 |
| Total Lines | 108 |
| Code Lines | 64 |
| 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 |
||
| 60 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
| 61 | { |
||
| 62 | if (!$var instanceof DOMNode) { |
||
| 63 | return; |
||
| 64 | } |
||
| 65 | |||
| 66 | // Fill the properties |
||
| 67 | // They can't be enumerated through reflection or casting, |
||
| 68 | // so we have to trust the docs and try them one at a time |
||
| 69 | $known_properties = array( |
||
| 70 | 'nodeValue', |
||
| 71 | 'childNodes', |
||
| 72 | 'attributes', |
||
| 73 | ); |
||
| 74 | |||
| 75 | if (self::$verbose) { |
||
| 76 | $known_properties = array( |
||
| 77 | 'nodeName', |
||
| 78 | 'nodeValue', |
||
| 79 | 'nodeType', |
||
| 80 | 'parentNode', |
||
| 81 | 'childNodes', |
||
| 82 | 'firstChild', |
||
| 83 | 'lastChild', |
||
| 84 | 'previousSibling', |
||
| 85 | 'nextSibling', |
||
| 86 | 'attributes', |
||
| 87 | 'ownerDocument', |
||
| 88 | 'namespaceURI', |
||
| 89 | 'prefix', |
||
| 90 | 'localName', |
||
| 91 | 'baseURI', |
||
| 92 | 'textContent', |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | $childNodes = array(); |
||
| 97 | $attributes = array(); |
||
| 98 | |||
| 99 | $rep = $o->value; |
||
| 100 | |||
| 101 | foreach ($known_properties as $prop) { |
||
| 102 | $prop_obj = $this->parseProperty($o, $prop, $var); |
||
| 103 | $rep->contents[] = $prop_obj; |
||
| 104 | |||
| 105 | if ($prop === 'childNodes') { |
||
| 106 | $childNodes = $prop_obj->getRepresentation('iterator'); |
||
| 107 | } elseif ($prop === 'attributes') { |
||
| 108 | $attributes = $prop_obj->getRepresentation('iterator'); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | if (!self::$verbose) { |
||
| 113 | $o->removeRepresentation('methods'); |
||
| 114 | $o->removeRepresentation('properties'); |
||
| 115 | } |
||
| 116 | |||
| 117 | // Attributes and comments and text nodes don't |
||
| 118 | // need children or attributes of their own |
||
| 119 | if (in_array($o->classname, array('DOMAttr', 'DOMText', 'DOMComment'))) { |
||
| 120 | return; |
||
| 121 | } |
||
| 122 | |||
| 123 | // Set the attributes |
||
| 124 | if ($attributes) { |
||
| 125 | $a = new Kint_Object_Representation('Attributes'); |
||
| 126 | foreach ($attributes->contents as $attribute) { |
||
| 127 | $a->contents[] = self::textualNodeToString($attribute); |
||
| 128 | } |
||
| 129 | $o->addRepresentation($a, 0); |
||
| 130 | } |
||
| 131 | |||
| 132 | // Set the children |
||
| 133 | if ($childNodes) { |
||
| 134 | $c = new Kint_Object_Representation('Children'); |
||
| 135 | |||
| 136 | if (count($childNodes->contents) === 1 && ($node = reset($childNodes->contents)) && in_array('depth_limit', $node->hints)) { |
||
| 137 | $node = $node->transplant(new Kint_Object_Instance()); |
||
| 138 | $node->name = 'childNodes'; |
||
| 139 | $node->classname = 'DOMNodeList'; |
||
| 140 | $c->contents = array($node); |
||
| 141 | } else { |
||
| 142 | foreach ($childNodes->contents as $index => $node) { |
||
| 143 | // Shortcircuit text nodes to plain strings |
||
| 144 | if ($node->classname === 'DOMText' || $node->classname === 'DOMComment') { |
||
| 145 | $node = self::textualNodeToString($node); |
||
| 146 | |||
| 147 | // And remove them if they're empty |
||
| 148 | if (ctype_space($node->value->contents) || $node->value->contents === '') { |
||
| 149 | continue; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $c->contents[] = $node; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $o->addRepresentation($c, 0); |
||
| 158 | } |
||
| 159 | |||
| 160 | if (isset($c) && count($c->contents)) { |
||
| 161 | $o->size = count($c->contents); |
||
| 162 | } |
||
| 163 | |||
| 164 | if (!$o->size) { |
||
| 165 | $o->size = null; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 227 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.