| Conditions | 10 |
| Paths | 13 |
| Total Lines | 42 |
| Code Lines | 21 |
| 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 |
||
| 15 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
| 16 | { |
||
| 17 | if (empty($o->value->contents)) { |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | $array = $this->parser->getCleanArray($var); |
||
| 22 | |||
| 23 | if (count($array) < 2) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | // Ensure this is an array of arrays and that all child arrays have the |
||
| 28 | // same keys. We don't care about their children - if there's another |
||
| 29 | // "table" inside we'll just make another one down the value tab |
||
| 30 | $keys = null; |
||
| 31 | foreach ($array as $elem) { |
||
| 32 | if (!is_array($elem) || count($elem) < 2) { |
||
| 33 | return; |
||
| 34 | } elseif ($keys === null) { |
||
| 35 | $keys = array_keys($elem); |
||
| 36 | } elseif (array_keys($elem) !== $keys) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | // Ensure none of the child arrays are recursion or depth limit. We |
||
| 42 | // don't care if their children are since they are the table cells |
||
| 43 | foreach ($o->value->contents as $childarray) { |
||
| 44 | if (empty($childarray->value->contents)) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | // Objects by reference for the win! We can do a copy-paste of the value |
||
| 50 | // representation contents and just slap a new hint on there and hey |
||
| 51 | // presto we have our table representation with no extra memory used! |
||
| 52 | $table = new Kint_Object_Representation('Table'); |
||
| 53 | $table->contents = $o->value->contents; |
||
| 54 | $table->hints[] = 'table'; |
||
| 55 | $o->addRepresentation($table, 0); |
||
| 56 | } |
||
| 57 | } |
||
| 58 |
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.