| Conditions | 13 |
| Paths | 20 |
| Total Lines | 101 |
| Code Lines | 66 |
| 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 |
||
| 258 | function getPosts($jodelAccount) |
||
| 259 | { |
||
| 260 | if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
||
| 261 | { |
||
| 262 | $accountCreator = new GetChannel(); |
||
| 263 | $accountCreator->view = $this->view; |
||
| 264 | $accountCreator->setAccessToken($jodelAccount->accessToken); |
||
| 265 | $accountCreator->channel = $this->hashtag; |
||
| 266 | $accountCreator->lastPostId = $this->lastPostId; |
||
| 267 | $data = $accountCreator->execute(); |
||
| 268 | } |
||
| 269 | else |
||
| 270 | { |
||
| 271 | if($this->lastPostId == '' && $this->view == 'combo') |
||
| 272 | { |
||
| 273 | $url = "/v3/posts/location/combo"; |
||
| 274 | } |
||
| 275 | else |
||
| 276 | { |
||
| 277 | if($this->view == 'discussed') |
||
| 278 | { |
||
| 279 | $url = "/v2/posts/location/discussed/"; |
||
| 280 | } |
||
| 281 | else |
||
| 282 | { |
||
| 283 | if($this->view == 'popular') |
||
| 284 | { |
||
| 285 | $url = "/v2/posts/location/popular/"; |
||
| 286 | } |
||
| 287 | else |
||
| 288 | { |
||
| 289 | $url = "/v2/posts/location/"; |
||
| 290 | } |
||
| 291 | } |
||
| 292 | } |
||
| 293 | |||
| 294 | $accountCreator = new GetPosts(); |
||
| 295 | $accountCreator->setLastPostId($this->lastPostId); |
||
| 296 | $accountCreator->setAccessToken($jodelAccount->accessToken); |
||
| 297 | $accountCreator->setUrl($url); |
||
| 298 | $accountCreator->version = 'v3'; |
||
| 299 | |||
| 300 | $config = parse_ini_file('config/config.ini.php'); |
||
| 301 | $location = new Location(); |
||
| 302 | $location->setLat($config['default_lat']); |
||
| 303 | $location->setLng($config['default_lng']); |
||
| 304 | $location->setCityName($config['default_location']); |
||
| 305 | $accountCreator->location = $location; |
||
| 306 | $data = $accountCreator->execute(); |
||
| 307 | } |
||
| 308 | if(array_key_exists('recent', $data) && array_key_exists(0, $data['recent'])) |
||
| 309 | { |
||
| 310 | return $data['recent']; |
||
| 311 | } |
||
| 312 | else if(array_key_exists('posts', $data)&& array_key_exists(0, $data['posts'])) |
||
| 313 | { |
||
| 314 | return $data['posts']; |
||
| 315 | } |
||
| 316 | else |
||
| 317 | { |
||
| 318 | if($this->lastPostId == '') |
||
| 319 | { |
||
| 320 | error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true)); |
||
| 321 | //error_log(print_r($data, true)); |
||
| 322 | |||
| 323 | $notFound[0] = array( |
||
| 324 | "post_id" => "0", |
||
| 325 | "discovered_by" => 0, |
||
| 326 | "message" => "No more Posts found", |
||
| 327 | "created_at" => "2017-02-11T16:44:50.385Z", |
||
| 328 | "updated_at" => "2017-02-11T16:44:50.385Z", |
||
| 329 | "pin_count" => 0, |
||
| 330 | "color" => "5682a3", |
||
| 331 | "got_thanks" => FALSE, |
||
| 332 | "post_own" => "friend", |
||
| 333 | "discovered" => 0, |
||
| 334 | "distance" => 9, |
||
| 335 | "vote_count" => 0, |
||
| 336 | "location" => |
||
| 337 | array("name" => "Berlin", |
||
| 338 | "loc_coordinates" => |
||
| 339 | array( |
||
| 340 | "lat" => 0, |
||
| 341 | "lng" => 0 |
||
| 342 | ), |
||
| 343 | "loc_accuracy" => 0, |
||
| 344 | "country" => "", |
||
| 345 | "city" => "", |
||
| 346 | ), |
||
| 347 | "tags" => |
||
| 348 | array(), |
||
| 349 | "user_handle" => "0" |
||
| 350 | ); |
||
| 351 | return $notFound; |
||
| 352 | } |
||
| 353 | else |
||
| 354 | { |
||
| 355 | return FALSE; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.