| Conditions | 19 |
| Paths | 326 |
| Total Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 156 | public function integrationLogs($service_id = NULL, $app_id = NULL, $user = NULL, $change_type = NULL, $count = 100, $page = 1) { |
||
| 157 | |||
| 158 | // Check if the type of the variables is valid. |
||
| 159 | if (!is_string($service_id) && ($service_id != NULL)) { |
||
| 160 | throw new InvalidArgumentException("The type of the service_id variable is not valid."); |
||
| 161 | } |
||
| 162 | if (!is_string($app_id) && ($app_id != NULL)) { |
||
| 163 | throw new InvalidArgumentException("The type of the app_id variable is not valid."); |
||
| 164 | } |
||
| 165 | if (!is_string($user) && ($user != NULL)) { |
||
| 166 | throw new InvalidArgumentException("The type of the user variable is not valid."); |
||
| 167 | } |
||
| 168 | if (!is_string($change_type) && ($change_type != NULL)) { |
||
| 169 | throw new InvalidArgumentException("The type of the change_type variable is not valid."); |
||
| 170 | } |
||
| 171 | if (!is_int($count)) { |
||
| 172 | throw new InvalidArgumentException("The type of the count variable is not valid."); |
||
| 173 | } |
||
| 174 | if (!is_string($page)) { |
||
| 175 | throw new InvalidArgumentException("The type of the page variable is not valid."); |
||
| 176 | } |
||
| 177 | |||
| 178 | // Set the arguments of the request |
||
| 179 | $arguments = array(); |
||
| 180 | |||
| 181 | if($service_id != NULL) { |
||
| 182 | $arguments["service_id"] = $service_id; |
||
| 183 | } |
||
| 184 | if($app_id != NULL) { |
||
| 185 | $arguments["app_id"] = $app_id; |
||
| 186 | } |
||
| 187 | if($user != NULL) { |
||
| 188 | $arguments["user"] = $user; |
||
| 189 | } |
||
| 190 | if($change_type != NULL) { |
||
| 191 | $arguments["change_type"] = $change_type; |
||
| 192 | } |
||
| 193 | if($count != NULL) { |
||
| 194 | $arguments["count"] = $count; |
||
| 195 | } |
||
| 196 | if($page != NULL) { |
||
| 197 | $arguments["page"] = $page; |
||
| 198 | } |
||
| 199 | |||
| 200 | $this->setUrl("team.integrationLogs", $arguments); |
||
| 201 | |||
| 202 | // Send the request |
||
| 203 | try { |
||
| 204 | $client = new \GuzzleHttp\Client(); |
||
| 205 | $json_response = $client->request('GET', $this->getUrl(), []); |
||
| 206 | $response = json_decode( $json_response->getBody() ); |
||
| 207 | } |
||
| 208 | catch (RequestException $e) { |
||
| 209 | throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); |
||
| 210 | } |
||
| 211 | |||
| 212 | if($response->{'ok'} === FALSE) { |
||
| 213 | throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); |
||
| 214 | } |
||
| 215 | |||
| 216 | return $json_response->getBody(); |
||
| 217 | } |
||
| 218 | |||
| 264 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.