| Conditions | 10 |
| Paths | 6 |
| Total Lines | 29 |
| Code Lines | 18 |
| 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 static function nodeToArray(Node $node) : array |
||
| 20 | { |
||
| 21 | $result = [ |
||
| 22 | 'kind' => $node->kind, |
||
| 23 | 'loc' => self::locationToArray($node->loc), |
||
| 24 | ]; |
||
| 25 | |||
| 26 | foreach (get_object_vars($node) as $prop => $propValue) { |
||
| 27 | if (isset($result[$prop])) { |
||
| 28 | continue; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (is_array($propValue) || $propValue instanceof NodeList) { |
||
| 32 | $tmp = []; |
||
| 33 | foreach ($propValue as $tmp1) { |
||
| 34 | $tmp[] = $tmp1 instanceof Node ? self::nodeToArray($tmp1) : (array) $tmp1; |
||
| 35 | } |
||
| 36 | } elseif ($propValue instanceof Node) { |
||
| 37 | $tmp = self::nodeToArray($propValue); |
||
| 38 | } elseif (is_scalar($propValue) || $propValue === null) { |
||
| 39 | $tmp = $propValue; |
||
| 40 | } else { |
||
| 41 | $tmp = null; |
||
| 42 | } |
||
| 43 | |||
| 44 | $result[$prop] = $tmp; |
||
| 45 | } |
||
| 46 | |||
| 47 | return $result; |
||
| 48 | } |
||
| 69 |