Complex classes like REST often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use REST, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class REST implements ServiceInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * REST adapter |
||
| 18 | * @var Client |
||
| 19 | */ |
||
| 20 | protected $adapter; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Application token |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $token; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Specifies the verbosity of the HTTP response |
||
| 30 | * 0 = basic, just body |
||
| 31 | * 1 = enhanced, [body, headers, status] |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | protected $responseVerbosity; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Initiate this REST service with the application token, a instance |
||
| 38 | * of the REST adapter (Guzzle) and a level of verbosity for the response. |
||
| 39 | * |
||
| 40 | * @param string $token |
||
| 41 | * @param Client $adapter |
||
| 42 | * @param int $responseVerbosity |
||
| 43 | */ |
||
| 44 | 45 | public function __construct($token, Client $adapter, $responseVerbosity = 0) |
|
| 53 | |||
| 54 | 44 | protected function getToken() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Get a request result. |
||
| 61 | * Returns an array with a response body or and error code => reason. |
||
| 62 | * @param Response $response |
||
| 63 | * @return array|mixed |
||
| 64 | */ |
||
| 65 | 44 | protected function getResult($response) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Get an API request response and handle possible exceptions. |
||
| 81 | * |
||
| 82 | * @param string $method |
||
| 83 | * @param string $path |
||
| 84 | * @param array $parameters |
||
| 85 | * |
||
| 86 | * @return array|mixed|string |
||
| 87 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 88 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 89 | */ |
||
| 90 | 44 | protected function getResponse($method, $path, $parameters) |
|
| 100 | |||
| 101 | 2 | public function getAthlete($id = null) |
|
| 102 | { |
||
| 103 | 2 | $path = 'athlete'; |
|
| 104 | 2 | if (isset($id) && $id !== null) { |
|
| 105 | 1 | $path = 'athletes/' . $id; |
|
| 106 | } |
||
| 107 | 2 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 108 | |||
| 109 | 2 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 110 | |||
| 111 | 2 | if ($this->responseVerbosity == 0) |
|
| 112 | 2 | return $response["body"]; |
|
| 113 | |||
| 114 | 2 | return $response; |
|
| 115 | } |
||
| 116 | |||
| 117 | 1 | public function getAthleteStats($id) |
|
| 118 | { |
||
| 119 | 1 | $path = 'athletes/' . $id . '/stats'; |
|
| 120 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 121 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 122 | |||
| 123 | 1 | if ($this->responseVerbosity == 0) |
|
| 124 | 1 | return $response['body']; |
|
| 125 | 1 | return $response; |
|
| 126 | } |
||
| 127 | |||
| 128 | 1 | public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null) |
|
| 129 | { |
||
| 130 | 1 | $path = 'athletes/' . $id . '/routes'; |
|
| 131 | 1 | $parameters['query'] = [ |
|
| 132 | 1 | 'type' => $type, |
|
| 133 | 1 | 'after' => $after, |
|
| 134 | 1 | 'page' => $page, |
|
| 135 | 1 | 'per_page' => $per_page, |
|
| 136 | 1 | 'access_token' => $this->getToken(), |
|
| 137 | ]; |
||
| 138 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 139 | |||
| 140 | 1 | if ($this->responseVerbosity == 0) |
|
| 141 | 1 | return $response['body']; |
|
| 142 | 1 | return $response; |
|
| 143 | } |
||
| 144 | |||
| 145 | 1 | public function getAthleteClubs() |
|
| 146 | { |
||
| 147 | 1 | $path = 'athlete/clubs'; |
|
| 148 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 149 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 150 | |||
| 151 | 1 | if ($this->responseVerbosity == 0) |
|
| 152 | 1 | return $response['body']; |
|
| 153 | 1 | return $response; |
|
| 154 | } |
||
| 155 | |||
| 156 | 1 | public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) |
|
| 157 | { |
||
| 158 | 1 | $path = 'athlete/activities'; |
|
| 159 | 1 | $parameters['query'] = [ |
|
| 160 | 1 | 'before' => $before, |
|
| 161 | 1 | 'after' => $after, |
|
| 162 | 1 | 'page' => $page, |
|
| 163 | 1 | 'per_page' => $per_page, |
|
| 164 | 1 | 'access_token' => $this->getToken(), |
|
| 165 | ]; |
||
| 166 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 167 | |||
| 168 | 1 | if ($this->responseVerbosity == 0) |
|
| 169 | 1 | return $response['body']; |
|
| 170 | 1 | return $response; |
|
| 171 | } |
||
| 172 | |||
| 173 | 2 | public function getAthleteFriends($id = null, $page = null, $per_page = null) |
|
| 174 | { |
||
| 175 | 2 | $path = 'athlete/friends'; |
|
| 176 | 2 | if (isset($id) && $id !== null) { |
|
| 177 | 1 | $path = 'athletes/' . $id . '/friends'; |
|
| 178 | } |
||
| 179 | 2 | $parameters['query'] = [ |
|
| 180 | 2 | 'page' => $page, |
|
| 181 | 2 | 'per_page' => $per_page, |
|
| 182 | 2 | 'access_token' => $this->getToken(), |
|
| 183 | ]; |
||
| 184 | 2 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 185 | |||
| 186 | 2 | if ($this->responseVerbosity == 0) |
|
| 187 | 2 | return $response['body']; |
|
| 188 | 2 | return $response; |
|
| 189 | } |
||
| 190 | |||
| 191 | 2 | public function getAthleteFollowers($id = null, $page = null, $per_page = null) |
|
| 192 | { |
||
| 193 | 2 | $path = 'athlete/followers'; |
|
| 194 | 2 | if (isset($id) && $id !== null) { |
|
| 195 | 1 | $path = 'athletes/' . $id . '/followers'; |
|
| 196 | } |
||
| 197 | 2 | $parameters['query'] = [ |
|
| 198 | 2 | 'page' => $page, |
|
| 199 | 2 | 'per_page' => $per_page, |
|
| 200 | 2 | 'access_token' => $this->getToken(), |
|
| 201 | ]; |
||
| 202 | 2 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 203 | |||
| 204 | 2 | if ($this->responseVerbosity == 0) |
|
| 205 | 2 | return $response['body']; |
|
| 206 | 2 | return $response; |
|
| 207 | } |
||
| 208 | |||
| 209 | 1 | public function getAthleteBothFollowing($id, $page = null, $per_page = null) |
|
| 210 | { |
||
| 211 | 1 | $path = 'athletes/' . $id . '/both-following'; |
|
| 212 | 1 | $parameters['query'] = [ |
|
| 213 | 1 | 'page' => $page, |
|
| 214 | 1 | 'per_page' => $per_page, |
|
| 215 | 1 | 'access_token' => $this->getToken(), |
|
| 216 | ]; |
||
| 217 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 218 | |||
| 219 | 1 | if ($this->responseVerbosity == 0) |
|
| 220 | 1 | return $response['body']; |
|
| 221 | 1 | return $response; |
|
| 222 | } |
||
| 223 | |||
| 224 | 1 | public function getAthleteKom($id, $page = null, $per_page = null) |
|
| 225 | { |
||
| 226 | 1 | $path = 'athletes/' . $id . '/koms'; |
|
| 227 | 1 | $parameters['query'] = [ |
|
| 228 | 1 | 'page' => $page, |
|
| 229 | 1 | 'per_page' => $per_page, |
|
| 230 | 1 | 'access_token' => $this->getToken(), |
|
| 231 | ]; |
||
| 232 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 233 | |||
| 234 | 1 | if ($this->responseVerbosity == 0) |
|
| 235 | 1 | return $response['body']; |
|
| 236 | 1 | return $response; |
|
| 237 | } |
||
| 238 | |||
| 239 | 1 | public function getAthleteZones() |
|
| 240 | { |
||
| 241 | 1 | $path = 'athlete/zones'; |
|
| 242 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 243 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 244 | |||
| 245 | 1 | if ($this->responseVerbosity == 0) |
|
| 246 | 1 | return $response['body']; |
|
| 247 | 1 | return $response; |
|
| 248 | } |
||
| 249 | |||
| 250 | 2 | public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) |
|
| 251 | { |
||
| 252 | 2 | $path = 'segments/starred'; |
|
| 253 | 2 | if (isset($id) && $id !== null) { |
|
| 254 | 1 | $path = 'athletes/' . $id . '/segments/starred'; |
|
| 255 | // ...wrong in Strava documentation |
||
| 256 | } |
||
| 257 | 2 | $parameters['query'] = [ |
|
| 258 | 2 | 'page' => $page, |
|
| 259 | 2 | 'per_page' => $per_page, |
|
| 260 | 2 | 'access_token' => $this->getToken(), |
|
| 261 | ]; |
||
| 262 | 2 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 263 | |||
| 264 | 2 | if ($this->responseVerbosity == 0) |
|
| 265 | 2 | return $response['body']; |
|
| 266 | 2 | return $response; |
|
| 267 | } |
||
| 268 | |||
| 269 | 1 | public function updateAthlete($city, $state, $country, $sex, $weight) |
|
| 270 | { |
||
| 271 | 1 | $path = 'athlete'; |
|
| 272 | 1 | $parameters['query'] = [ |
|
| 273 | 1 | 'city' => $city, |
|
| 274 | 1 | 'state' => $state, |
|
| 275 | 1 | 'country' => $country, |
|
| 276 | 1 | 'sex' => $sex, |
|
| 277 | 1 | 'weight' => $weight, |
|
| 278 | 1 | 'access_token' => $this->getToken(), |
|
| 279 | ]; |
||
| 280 | 1 | $response = $this->getResponse('PUT', $path, $parameters); |
|
| 281 | |||
| 282 | 1 | if ($this->responseVerbosity == 0) |
|
| 283 | 1 | return $response['body']; |
|
| 284 | 1 | return $response; |
|
| 285 | } |
||
| 286 | |||
| 287 | 1 | public function getActivity($id, $include_all_efforts = null) |
|
| 288 | { |
||
| 289 | 1 | $path = 'activities/' . $id; |
|
| 290 | 1 | $parameters['query'] = [ |
|
| 291 | 1 | 'include_all_efforts' => $include_all_efforts, |
|
| 292 | 1 | 'access_token' => $this->getToken(), |
|
| 293 | ]; |
||
| 294 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 295 | |||
| 296 | 1 | if ($this->responseVerbosity == 0) |
|
| 297 | 1 | return $response['body']; |
|
| 298 | 1 | return $response; |
|
| 299 | } |
||
| 300 | |||
| 301 | 1 | public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) |
|
| 302 | { |
||
| 303 | 1 | $path = 'activities/' . $id . '/comments'; |
|
| 304 | 1 | $parameters['query'] = [ |
|
| 305 | 1 | 'markdown' => $markdown, |
|
| 306 | 1 | 'page' => $page, |
|
| 307 | 1 | 'per_page' => $per_page, |
|
| 308 | 1 | 'access_token' => $this->getToken(), |
|
| 309 | ]; |
||
| 310 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 311 | |||
| 312 | 1 | if ($this->responseVerbosity == 0) |
|
| 313 | 1 | return $response['body']; |
|
| 314 | 1 | return $response; |
|
| 315 | } |
||
| 316 | |||
| 317 | 1 | public function getActivityKudos($id, $page = null, $per_page = null) |
|
| 318 | { |
||
| 319 | 1 | $path = 'activities/' . $id . '/kudos'; |
|
| 320 | 1 | $parameters['query'] = [ |
|
| 321 | 1 | 'page' => $page, |
|
| 322 | 1 | 'per_page' => $per_page, |
|
| 323 | 1 | 'access_token' => $this->getToken(), |
|
| 324 | ]; |
||
| 325 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 326 | |||
| 327 | 1 | if ($this->responseVerbosity == 0) |
|
| 328 | 1 | return $response['body']; |
|
| 329 | 1 | return $response; |
|
| 330 | } |
||
| 331 | |||
| 332 | 1 | public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') |
|
| 333 | { |
||
| 334 | 1 | $path = 'activities/' . $id . '/photos'; |
|
| 335 | 1 | $parameters['query'] = [ |
|
| 336 | 1 | 'size' => $size, |
|
| 337 | 1 | 'photo_sources' => $photo_sources, |
|
| 338 | 1 | 'access_token' => $this->getToken(), |
|
| 339 | ]; |
||
| 340 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 341 | |||
| 342 | 1 | if ($this->responseVerbosity == 0) |
|
| 343 | 1 | return $response['body']; |
|
| 344 | 1 | return $response; |
|
| 345 | } |
||
| 346 | |||
| 347 | 1 | public function getActivityZones($id) |
|
| 348 | { |
||
| 349 | 1 | $path = 'activities/' . $id . '/zones'; |
|
| 350 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 351 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 352 | |||
| 353 | 1 | if ($this->responseVerbosity == 0) |
|
| 354 | 1 | return $response['body']; |
|
| 355 | 1 | return $response; |
|
| 356 | } |
||
| 357 | |||
| 358 | 1 | public function getActivityLaps($id) |
|
| 359 | { |
||
| 360 | 1 | $path = 'activities/' . $id . '/laps'; |
|
| 361 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 362 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 363 | |||
| 364 | 1 | if ($this->responseVerbosity == 0) |
|
| 365 | 1 | return $response['body']; |
|
| 366 | 1 | return $response; |
|
| 367 | } |
||
| 368 | |||
| 369 | 1 | public function getActivityUploadStatus($id) |
|
| 370 | { |
||
| 371 | 1 | $path = 'uploads/' . $id; |
|
| 372 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 373 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 374 | |||
| 375 | 1 | if ($this->responseVerbosity == 0) |
|
| 376 | 1 | return $response['body']; |
|
| 377 | 1 | return $response; |
|
| 378 | } |
||
| 379 | |||
| 380 | 1 | public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null, $private = null, $trainer = null) |
|
| 381 | { |
||
| 382 | 1 | $path = 'activities'; |
|
| 383 | 1 | $parameters['query'] = [ |
|
| 384 | 1 | 'name' => $name, |
|
| 385 | 1 | 'type' => $type, |
|
| 386 | 1 | 'start_date_local' => $start_date_local, |
|
| 387 | 1 | 'elapsed_time' => $elapsed_time, |
|
| 388 | 1 | 'description' => $description, |
|
| 389 | 1 | 'distance' => $distance, |
|
| 390 | 1 | 'private' => $private, |
|
| 391 | 1 | 'trainer' => $trainer, |
|
| 392 | 1 | 'access_token' => $this->getToken(), |
|
| 393 | ]; |
||
| 394 | 1 | $response = $this->getResponse('POST', $path, $parameters); |
|
| 395 | |||
| 396 | 1 | if ($this->responseVerbosity == 0) |
|
| 397 | 1 | return $response['body']; |
|
| 398 | 1 | return $response; |
|
| 399 | } |
||
| 400 | |||
| 401 | 1 | public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) |
|
| 402 | { |
||
| 403 | 1 | $path = 'uploads'; |
|
| 404 | 1 | $parameters['query'] = [ |
|
| 405 | 1 | 'activity_type' => $activity_type, |
|
| 406 | 1 | 'name' => $name, |
|
| 407 | 1 | 'description' => $description, |
|
| 408 | 1 | 'private' => $private, |
|
| 409 | 1 | 'trainer' => $trainer, |
|
| 410 | 1 | 'commute' => $commute, |
|
| 411 | 1 | 'data_type' => $data_type, |
|
| 412 | 1 | 'external_id' => $external_id, |
|
| 413 | 1 | 'file' => curl_file_create($file), |
|
| 414 | 1 | 'file_hack' => '@' . ltrim($file, '@'), |
|
| 415 | 1 | 'access_token' => $this->getToken(), |
|
| 416 | ]; |
||
| 417 | 1 | $response = $this->getResponse('POST', $path, $parameters); |
|
| 418 | |||
| 419 | 1 | if ($this->responseVerbosity == 0) |
|
| 420 | 1 | return $response['body']; |
|
| 421 | 1 | return $response; |
|
| 422 | } |
||
| 423 | |||
| 424 | 1 | public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) |
|
| 425 | { |
||
| 426 | 1 | $path = 'activities/' . $id; |
|
| 427 | 1 | $parameters['query'] = [ |
|
| 428 | 1 | 'name' => $name, |
|
| 429 | 1 | 'type' => $type, |
|
| 430 | 1 | 'private' => $private, |
|
| 431 | 1 | 'commute' => $commute, |
|
| 432 | 1 | 'trainer' => $trainer, |
|
| 433 | 1 | 'gear_id' => $gear_id, |
|
| 434 | 1 | 'description' => $description, |
|
| 435 | 1 | 'access_token' => $this->getToken(), |
|
| 436 | ]; |
||
| 437 | 1 | $response = $this->getResponse('PUT', $path, $parameters); |
|
| 438 | |||
| 439 | 1 | if ($this->responseVerbosity == 0) |
|
| 440 | 1 | return $response['body']; |
|
| 441 | 1 | return $response; |
|
| 442 | } |
||
| 443 | |||
| 444 | 1 | public function deleteActivity($id) |
|
| 445 | { |
||
| 446 | 1 | $path = 'activities/' . $id; |
|
| 447 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 448 | 1 | $response = $this->getResponse('DELETE', $path, $parameters); |
|
| 449 | |||
| 450 | 1 | if ($this->responseVerbosity == 0) |
|
| 451 | 1 | return $response['body']; |
|
| 452 | 1 | return $response; |
|
| 453 | } |
||
| 454 | |||
| 455 | 1 | public function getGear($id) |
|
| 456 | { |
||
| 457 | 1 | $path = 'gear/' . $id; |
|
| 458 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 459 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 460 | |||
| 461 | 1 | if ($this->responseVerbosity == 0) |
|
| 462 | 1 | return $response['body']; |
|
| 463 | 1 | return $response; |
|
| 464 | } |
||
| 465 | |||
| 466 | 1 | public function getClub($id) |
|
| 467 | { |
||
| 468 | 1 | $path = 'clubs/' . $id; |
|
| 469 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 470 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 471 | |||
| 472 | 1 | if ($this->responseVerbosity == 0) |
|
| 473 | 1 | return $response['body']; |
|
| 474 | 1 | return $response; |
|
| 475 | } |
||
| 476 | |||
| 477 | 1 | public function getClubMembers($id, $page = null, $per_page = null) |
|
| 478 | { |
||
| 479 | 1 | $path = 'clubs/' . $id . '/members'; |
|
| 480 | 1 | $parameters['query'] = [ |
|
| 481 | 1 | 'page' => $page, |
|
| 482 | 1 | 'per_page' => $per_page, |
|
| 483 | 1 | 'access_token' => $this->getToken(), |
|
| 484 | ]; |
||
| 485 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 486 | |||
| 487 | 1 | if ($this->responseVerbosity == 0) |
|
| 488 | 1 | return $response['body']; |
|
| 489 | 1 | return $response; |
|
| 490 | } |
||
| 491 | |||
| 492 | 1 | public function getClubActivities($id, $page = null, $per_page = null) |
|
| 493 | { |
||
| 494 | 1 | $path = 'clubs/' . $id . '/activities'; |
|
| 495 | 1 | $parameters['query'] = [ |
|
| 496 | 1 | 'page' => $page, |
|
| 497 | 1 | 'per_page' => $per_page, |
|
| 498 | 1 | 'access_token' => $this->getToken(), |
|
| 499 | ]; |
||
| 500 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 501 | |||
| 502 | 1 | if ($this->responseVerbosity == 0) |
|
| 503 | 1 | return $response['body']; |
|
| 504 | 1 | return $response; |
|
| 505 | } |
||
| 506 | |||
| 507 | 1 | public function getClubAnnouncements($id) |
|
| 508 | { |
||
| 509 | 1 | $path = 'clubs/' . $id . '/announcements'; |
|
| 510 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 511 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 512 | |||
| 513 | 1 | if ($this->responseVerbosity == 0) |
|
| 514 | 1 | return $response['body']; |
|
| 515 | 1 | return $response; |
|
| 516 | } |
||
| 517 | |||
| 518 | 1 | public function getClubGroupEvents($id) |
|
| 519 | { |
||
| 520 | 1 | $path = 'clubs/' . $id . '/group_events'; |
|
| 521 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 522 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 523 | |||
| 524 | 1 | if ($this->responseVerbosity == 0) |
|
| 525 | 1 | return $response['body']; |
|
| 526 | 1 | return $response; |
|
| 527 | } |
||
| 528 | |||
| 529 | 1 | public function joinClub($id) |
|
| 530 | { |
||
| 531 | 1 | $path = 'clubs/' . $id . '/join'; |
|
| 532 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 533 | 1 | $response = $this->getResponse('POST', $path, $parameters); |
|
| 534 | |||
| 535 | 1 | if ($this->responseVerbosity == 0) |
|
| 536 | 1 | return $response['body']; |
|
| 537 | 1 | return $response; |
|
| 538 | } |
||
| 539 | |||
| 540 | 1 | public function leaveClub($id) |
|
| 541 | { |
||
| 542 | 1 | $path = 'clubs/' . $id . '/leave'; |
|
| 543 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 544 | 1 | $response = $this->getResponse('POST', $path, $parameters); |
|
| 545 | |||
| 546 | 1 | if ($this->responseVerbosity == 0) |
|
| 547 | 1 | return $response['body']; |
|
| 548 | 1 | return $response; |
|
| 549 | } |
||
| 550 | |||
| 551 | 1 | public function getRoute($id) |
|
| 552 | { |
||
| 553 | 1 | $path = 'routes/' . $id; |
|
| 554 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 555 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 556 | |||
| 557 | 1 | if ($this->responseVerbosity == 0) |
|
| 558 | 1 | return $response['body']; |
|
| 559 | 1 | return $response; |
|
| 560 | } |
||
| 561 | |||
| 562 | public function getRouteAsGPX($id) |
||
| 572 | |||
| 573 | public function getRouteAsTCX($id) |
||
| 583 | |||
| 584 | 1 | public function getSegment($id) |
|
| 585 | { |
||
| 586 | 1 | $path = 'segments/' . $id; |
|
| 587 | 1 | $parameters['query'] = ['access_token' => $this->getToken()]; |
|
| 588 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 589 | |||
| 590 | 1 | if ($this->responseVerbosity == 0) |
|
| 591 | 1 | return $response['body']; |
|
| 592 | 1 | return $response; |
|
| 593 | } |
||
| 594 | |||
| 595 | 1 | public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $context_entries = null, $page = null, $per_page = null) |
|
| 596 | { |
||
| 597 | 1 | $path = 'segments/' . $id . '/leaderboard'; |
|
| 598 | 1 | $parameters['query'] = [ |
|
| 599 | 1 | 'gender' => $gender, |
|
| 600 | 1 | 'age_group' => $age_group, |
|
| 601 | 1 | 'weight_class' => $weight_class, |
|
| 602 | 1 | 'following' => $following, |
|
| 603 | 1 | 'club_id' => $club_id, |
|
| 604 | 1 | 'date_range' => $date_range, |
|
| 605 | 1 | 'context_entries' => $context_entries, |
|
| 606 | 1 | 'page' => $page, |
|
| 607 | 1 | 'per_page' => $per_page, |
|
| 608 | 1 | 'access_token' => $this->getToken(), |
|
| 609 | ]; |
||
| 610 | 1 | $response = $this->getResponse('GET', $path, $parameters); |
|
| 611 | |||
| 612 | 1 | if ($this->responseVerbosity == 0) |
|
| 613 | 1 | return $response['body']; |
|
| 614 | 1 | return $response; |
|
| 615 | } |
||
| 616 | |||
| 617 | 1 | public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) |
|
| 633 | |||
| 634 | 1 | public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) |
|
| 651 | |||
| 652 | 1 | public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') |
|
| 666 | |||
| 667 | 1 | public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') |
|
| 681 | |||
| 682 | 1 | public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') |
|
| 696 | |||
| 697 | 1 | public function getStreamsRoute($id) |
|
| 707 | |||
| 708 | } |
||
| 709 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.