| Conditions | 10 | 
| Paths | 72 | 
| Total Lines | 50 | 
| 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  | 
            ||
| 33 | public function toArray(  | 
            ||
| 34 | array $fields = [],  | 
            ||
| 35 | array $expand = [],  | 
            ||
| 36 | $recursive = true  | 
            ||
| 37 |     ) { | 
            ||
| 38 | $data = [];  | 
            ||
| 39 |         foreach ($this->resolveFieldList($fields) as $field => $definition) { | 
            ||
| 40 | $data[$field] = $this->processField($field, $definition);  | 
            ||
| 41 | }  | 
            ||
| 42 | |||
| 43 |         foreach ($this->resolveExpandList($expand) as $field => $definition) { | 
            ||
| 44 | $attribute = $this->processField($field, $definition);  | 
            ||
| 45 | |||
| 46 |             if ($recursive) { | 
            ||
| 47 | $nestedFields = $this->extractFieldsFor($fields, $field);  | 
            ||
| 48 | $nestedExpand = $this->extractFieldsFor($expand, $field);  | 
            ||
| 49 |                 if ($attribute instanceof Arrayable) { | 
            ||
| 50 | $attribute = $attribute->toArray(  | 
            ||
| 51 | $nestedFields,  | 
            ||
| 52 | $nestedExpand  | 
            ||
| 53 | );  | 
            ||
| 54 |                 } elseif (is_array($attribute)) { | 
            ||
| 55 | $attribute = array_map(  | 
            ||
| 56 |                         function ($item) use ($nestedFields, $nestedExpand) { | 
            ||
| 57 |                             if ($item instanceof Arrayable) { | 
            ||
| 58 | return $item->toArray(  | 
            ||
| 59 | $nestedFields,  | 
            ||
| 60 | $nestedExpand  | 
            ||
| 61 | );  | 
            ||
| 62 | }  | 
            ||
| 63 | return $item;  | 
            ||
| 64 | },  | 
            ||
| 65 | $attribute  | 
            ||
| 66 | );  | 
            ||
| 67 | }  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 70 |             if ($envelope = $this->getExpandEnvelope()) { | 
            ||
| 71 | $data[$envelope][$field] = $attribute;  | 
            ||
| 72 |             } else { | 
            ||
| 73 | $data[$field] = $attribute;  | 
            ||
| 74 | }  | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 |         if ($this instanceof Linkable) { | 
            ||
| 78 | $data['_links'] = Link::serialize($this->getLinks());  | 
            ||
| 79 | }  | 
            ||
| 80 | |||
| 81 | return $recursive ? ArrayHelper::toArray($data) : $data;  | 
            ||
| 82 | }  | 
            ||
| 83 | |||
| 171 | 
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.