Conditions | 25 |
Paths | 3 |
Total Lines | 69 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
9 | public function getResponse() |
||
10 | { |
||
11 | $response = parent::getResponse(); |
||
12 | if (isset($response['columns'], $response['data'])) { |
||
13 | $data = []; |
||
14 | array_walk($response['columns'], static function (&$value, $key) { |
||
|
|||
15 | $value = array_keys($value)[0]; |
||
16 | }); |
||
17 | $id = -1; |
||
18 | foreach ($response['data'] as $property) { |
||
19 | if (isset($property['id'])) { |
||
20 | $id = $property['id']; |
||
21 | if (count($property) > 1) { |
||
22 | unset($property['id']); |
||
23 | } |
||
24 | } elseif (isset($this->params['customMapping']) and $this->params['customMapping']) { |
||
25 | if (isset($property['Field'])) { |
||
26 | $id = $property['Field']; |
||
27 | if (count($property) > 1) { |
||
28 | unset($property['Field']); |
||
29 | } |
||
30 | } elseif (isset($property['Variable_name'])) { |
||
31 | $id = $property['Variable_name']; |
||
32 | if (count($property) > 1) { |
||
33 | unset($property['Variable_name']); |
||
34 | } |
||
35 | } elseif (isset($property['Index'])) { |
||
36 | $id = $property['Index']; |
||
37 | if (count($property) > 1) { |
||
38 | unset($property['Index']); |
||
39 | } |
||
40 | } elseif (isset($property['Counter'])) { |
||
41 | $id = $property['Counter']; |
||
42 | if (count($property) > 1) { |
||
43 | unset($property['Counter']); |
||
44 | } |
||
45 | } elseif (isset($property['Key'])) { |
||
46 | $id = $property['Key']; |
||
47 | if (count($property) > 1) { |
||
48 | unset($property['Key']); |
||
49 | } |
||
50 | } elseif (isset($property['command'])) { |
||
51 | $id = $property['command']; |
||
52 | if (count($property) > 1) { |
||
53 | unset($property['command']); |
||
54 | } |
||
55 | } elseif (isset($property['suggest'])) { |
||
56 | $id = $property['suggest']; |
||
57 | if (count($property) > 1) { |
||
58 | unset($property['suggest']); |
||
59 | } |
||
60 | } elseif (isset($property['Variable'])) { |
||
61 | $id = $property['Variable']; |
||
62 | if (count($property) > 1) { |
||
63 | unset($property['Variable']); |
||
64 | } |
||
65 | } else { |
||
66 | $id++; |
||
67 | } |
||
68 | } else { |
||
69 | $id++; |
||
70 | } |
||
71 | $data[$id] = (count($property) == 1)?array_shift($property):$property; |
||
72 | } |
||
73 | if (count($data) > 0) { |
||
74 | return $data; |
||
75 | } |
||
76 | } |
||
77 | return $response; |
||
78 | } |
||
80 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.