| Conditions | 16 |
| Paths | 16 |
| Total Lines | 36 |
| Code Lines | 25 |
| Lines | 12 |
| Ratio | 33.33 % |
| 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 |
||
| 37 | public function parse($rawBody, $contentType) |
||
| 38 | { |
||
| 39 | $array = parent::parse($rawBody, $contentType); |
||
| 40 | if ($type = ArrayHelper::getValue($array, 'data.type')) { |
||
| 41 | $formName = call_user_func($this->formNameCallback, $type); |
||
| 42 | if ($attributes = ArrayHelper::getValue($array, 'data.attributes')) { |
||
| 43 | $result[$formName] = $attributes; |
||
| 44 | } elseif ($id = ArrayHelper::getValue($array, 'data.id')) { |
||
| 45 | $result[$formName] = ['id' => $id, 'type' => $type]; |
||
| 46 | } |
||
| 47 | if ($relationships = ArrayHelper::getValue($array, 'data.relationships')) { |
||
| 48 | foreach ($relationships as $name => $relationship) { |
||
| 49 | if (isset($relationship[0])) { |
||
| 50 | View Code Duplication | foreach ($relationship as $item) { |
|
| 51 | if (isset($item['type']) && isset($item['id'])) { |
||
| 52 | $formName = call_user_func($this->formNameCallback, $item['type']); |
||
| 53 | $result[$name][$formName][] = $item; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } elseif (isset($relationship['type']) && isset($relationship['id'])) { |
||
| 57 | $formName = call_user_func($this->formNameCallback, $relationship['type']); |
||
| 58 | $result[$name][$formName] = $relationship; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } else { |
||
| 63 | $data = ArrayHelper::getValue($array, 'data', []); |
||
| 64 | View Code Duplication | foreach ($data as $relationLink) { |
|
| 65 | if (isset($relationLink['type']) && isset($relationLink['id'])) { |
||
| 66 | $formName = call_user_func($this->formNameCallback, $relationLink['type']); |
||
| 67 | $result[$formName][] = $relationLink; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | return isset($result) ? $result : $array; |
||
| 72 | } |
||
| 73 | |||
| 79 |