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