| Conditions | 10 |
| Paths | 7 |
| Total Lines | 32 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 10 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 24 | 18 | private function prepareJsonData($data) |
|
| 25 | { |
||
| 26 | 18 | if (is_object($data)) { |
|
| 27 | 7 | if ($data instanceof JsonSerializable) { |
|
| 28 | 1 | return $this->prepareJsonData($data->jsonSerialize()); |
|
| 29 | } |
||
| 30 | |||
| 31 | 6 | if ($data instanceof DateTimeInterface) { |
|
| 32 | 1 | return $this->prepareJsonData((array) $data); |
|
| 33 | } |
||
| 34 | |||
| 35 | 5 | $object = $data; |
|
| 36 | 5 | $data = []; |
|
| 37 | |||
| 38 | 5 | foreach ($object as $name => $value) { |
|
| 39 | 4 | $data[$name] = $value; |
|
| 40 | } |
||
| 41 | |||
| 42 | 5 | if ($data === []) { |
|
| 43 | 4 | return new stdClass(); |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | 18 | if (is_array($data)) { |
|
| 48 | 17 | foreach ($data as $key => $value) { |
|
| 49 | 16 | if (is_array($value) || is_object($value)) { |
|
| 50 | 6 | $data[$key] = $this->prepareJsonData($value); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | 18 | return $data; |
|
| 56 | } |
||
| 58 |