| Conditions | 11 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 8 |
| 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 |
||
| 18 | public function parse($rawBody, $contentType) |
||
| 19 | { |
||
| 20 | $array = parent::parse($rawBody, $contentType); |
||
| 21 | if ($type = ArrayHelper::getValue($array, 'data.type')) { |
||
| 22 | $formName = Inflector::id2camel(Inflector::singularize($type)); |
||
|
|
|||
| 23 | $result[$formName] = ArrayHelper::getValue($array, 'data.attributes'); |
||
| 24 | if ($relationships = ArrayHelper::getValue($array, 'data.relationships')) { |
||
| 25 | foreach ($relationships as $name => $relationship) { |
||
| 26 | if (isset($relationship[0])) { |
||
| 27 | foreach ($relationship as $item) { |
||
| 28 | View Code Duplication | if (isset($item['type']) && isset($item['id'])) { |
|
| 29 | $formName = Inflector::id2camel(Inflector::singularize($item['type'])); |
||
| 30 | $result[$name][$formName][] = $item; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | View Code Duplication | } elseif (isset($relationship['type']) && isset($relationship['id'])) { |
|
| 34 | $formName = Inflector::id2camel(Inflector::singularize($relationship['type'])); |
||
| 35 | $result[$name][$formName] = $relationship; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | return isset($result) ? $result : $array; |
||
| 41 | } |
||
| 42 | } |
||
| 43 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.