Conditions | 11 |
Paths | 22 |
Total Lines | 48 |
Code Lines | 29 |
Lines | 17 |
Ratio | 35.42 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
103 | public function addMember($group_name = null, $data = array()) |
||
104 | { |
||
105 | if (!$group_name || !$data) { |
||
106 | return false; |
||
107 | } |
||
108 | |||
109 | // Obtained with the command: ipa -vv group_add_member group_one --users="stallman" |
||
110 | $args = array($group_name); |
||
111 | $default_options = array( |
||
112 | 'all' => true, |
||
113 | 'no_members' => false, |
||
114 | 'raw' => false, |
||
115 | ); |
||
116 | View Code Duplication | if (is_array($data)) { |
|
117 | $final_options = array_merge($default_options, $data); |
||
118 | } else if (is_string($data)) { |
||
119 | $final_options = array_merge($default_options, array('user' => array($data))); |
||
120 | } else { |
||
121 | return false; |
||
122 | } |
||
123 | |||
124 | $response = $this->getConnection()->buildRequest('group_add_member', $args, $final_options); //returns json and http code of response |
||
125 | if (!$response) { |
||
126 | return false; |
||
127 | } |
||
128 | $returned_json = $response[0]; |
||
129 | if (!$returned_json->result->completed) { |
||
130 | $message = "Error while inserting members in group \"$group_name\"."; |
||
131 | View Code Duplication | if (!empty($returned_json->result->failed->member->group) || |
|
132 | !empty($returned_json->result->failed->member->user)) { |
||
133 | $message .= 'Details: '; |
||
134 | } |
||
135 | |||
136 | View Code Duplication | if (!empty($returned_json->result->failed->member->group)) { |
|
137 | $message .= implode(' ', $returned_json->result->failed->member->group[0]); |
||
138 | } |
||
139 | |||
140 | View Code Duplication | if (!empty($returned_json->result->failed->member->user)) { |
|
141 | $message .= implode(' ', $returned_json->result->failed->member->user[0]); |
||
142 | } |
||
143 | |||
144 | throw new \Exception($message); |
||
145 | } |
||
146 | |||
147 | // Unlike other methods, where $returned_json->result->result is returned, |
||
148 | // here the $returned_json->result contain usefull information |
||
149 | return $returned_json->result; |
||
150 | } |
||
151 | } |
||
152 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.