| Conditions | 12 |
| Paths | 13 |
| Total Lines | 62 |
| Code Lines | 38 |
| 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 |
||
| 19 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
| 20 | { |
||
| 21 | if (!($var instanceof DOMNamedNodeMap || $var instanceof DOMNodeList)) { |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | |||
| 25 | $o->size = $var->length; |
||
| 26 | if ($o->size === 0) { |
||
| 27 | $o->replaceRepresentation(new Kint_Object_Representation('Iterator')); |
||
| 28 | $o->size = null; |
||
| 29 | |||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | // Depth limit |
||
| 34 | // Make empty iterator representation since we need it in DOMNode to point out depth limits |
||
| 35 | if ($this->parser->max_depth && $o->depth + 1 >= $this->parser->max_depth) { |
||
| 36 | $b = new Kint_Object(); |
||
| 37 | $b->name = $o->classname.' Iterator Contents'; |
||
| 38 | $b->access_path = 'iterator_to_array('.$o->access_path.')'; |
||
| 39 | $b->depth = $o->depth + 1; |
||
| 40 | $b->hints[] = 'depth_limit'; |
||
| 41 | |||
| 42 | $r = new Kint_Object_Representation('Iterator'); |
||
| 43 | $r->contents = array($b); |
||
| 44 | $o->replaceRepresentation($r, 0); |
||
| 45 | |||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | // In 5.1 you can interate them but they're not traversable. |
||
| 50 | // DomDoc. The gift that keeps on giving. |
||
| 51 | if (!$var instanceof Traversable) { |
||
| 52 | $data = array(); |
||
| 53 | foreach ($var as $item) { |
||
| 54 | $data[] = $item; |
||
| 55 | } |
||
| 56 | } else { |
||
| 57 | $data = iterator_to_array($var); |
||
| 58 | } |
||
| 59 | |||
| 60 | $r = new Kint_Object_Representation('Iterator'); |
||
| 61 | $o->replaceRepresentation($r, 0); |
||
| 62 | |||
| 63 | foreach ($data as $key => $item) { |
||
| 64 | $base_obj = new Kint_Object(); |
||
| 65 | $base_obj->depth = $o->depth + 1; |
||
| 66 | $base_obj->name = $item->nodeName; |
||
| 67 | |||
| 68 | if ($o->access_path) { |
||
| 69 | if ($var instanceof DOMNamedNodeMap) { |
||
| 70 | $base_obj->access_path = $o->access_path.'->getNamedItem('.var_export($key, true).')'; |
||
| 71 | } elseif ($var instanceof DOMNodeList) { |
||
| 72 | $base_obj->access_path = $o->access_path.'->item('.var_export($key, true).')'; |
||
| 73 | } else { |
||
| 74 | $base_obj->access_path = 'iterator_to_array('.$o->access_path.')'; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $r->contents[] = $this->parser->parse($item, $base_obj); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.