| Conditions | 11 |
| Paths | 48 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 6 |
| Ratio | 21.43 % |
| 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 |
||
| 49 | public function export($transformer=null, $disabled_relations=[]){ |
||
| 50 | $data = []; |
||
| 51 | if (!is_callable($transformer)) $transformer = function($k,$v){ return [$k=>$v]; }; |
||
| 52 | foreach (get_object_vars($this) as $key => $value) { |
||
| 53 | View Code Duplication | if ($res = $transformer($key, $value)){ |
|
| 54 | $data[key($res)] = current($res); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | foreach (static::relationOptions()->links as $hash => $link) { |
||
| 59 | $relation = $link->method; |
||
| 60 | // Expand relations but protect from self-references loop |
||
| 61 | if (isset($disabled_relations[$hash])) continue; |
||
| 62 | $disabled_relations[$hash] = true; |
||
| 63 | $value = $this->$relation; |
||
| 64 | if ($value && is_array($value)) |
||
| 65 | foreach ($value as &$val) $val = $val->export(null,$disabled_relations); |
||
| 66 | else |
||
| 67 | $value = $value ? $value->export(null,$disabled_relations) : false; |
||
| 68 | unset($disabled_relations[$hash]); |
||
| 69 | |||
| 70 | View Code Duplication | if ($res = $transformer($relation, $value)){ |
|
| 71 | $data[key($res)] = current($res); |
||
| 72 | } |
||
| 73 | |||
| 74 | } |
||
| 75 | return $data; |
||
| 76 | } |
||
| 77 | |||
| 83 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.