Complex classes like WowService 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 WowService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class WowService extends BattlenetHttpClient |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * {@inheritdoc} |
||
| 14 | */ |
||
| 15 | protected $gameParam = '/wow'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Get achievement information by id. |
||
| 19 | * |
||
| 20 | * This provides data about an individual achievement |
||
| 21 | * |
||
| 22 | * @param int $achievementId Id of the achievement to retrieve |
||
| 23 | * @param array $options Options |
||
| 24 | * |
||
| 25 | * @return Illuminate\Support\Collection api response |
||
| 26 | */ |
||
| 27 | public function getAchievement($achievementId, array $options = []) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get auction data. |
||
| 34 | * |
||
| 35 | * Auction APIs currently provide rolling batches of data about current auctions. Fetching auction dumps is a two |
||
| 36 | * step process that involves checking a per-realm index file to determine if a recent dump has been generated and |
||
| 37 | * then fetching the most recently generated dump file if necessary. |
||
| 38 | * |
||
| 39 | * This API resource provides a per-realm list of recently generated auction house data dumps |
||
| 40 | * |
||
| 41 | * @param string $realm Realm being requested |
||
| 42 | * @param array $options Options |
||
| 43 | * |
||
| 44 | * @return Illuminate\Support\Collection api response |
||
| 45 | */ |
||
| 46 | public function getAuctionDataStatus($realm, array $options = []) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get boss master list. |
||
| 53 | * |
||
| 54 | * A list of all supported bosses. A 'boss' in this context should be considered a boss encounter, which may include |
||
| 55 | * more than one NPC. |
||
| 56 | * |
||
| 57 | * @param array $options Options |
||
| 58 | * |
||
| 59 | * @return Illuminate\Support\Collection api response |
||
| 60 | */ |
||
| 61 | public function getBossMasterList(array $options = []) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get boss information by id. |
||
| 68 | * |
||
| 69 | * The boss API provides information about bosses. A 'boss' in this context should be considered a boss encounter, |
||
| 70 | * which may include more than one NPC. |
||
| 71 | * |
||
| 72 | * @param int $bossId Id of the boss you want to retrieve |
||
| 73 | * @param array $options Options |
||
| 74 | * |
||
| 75 | * @return Illuminate\Support\Collection api response |
||
| 76 | */ |
||
| 77 | public function getBoss($bossId, array $options = []) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get realm leaderboards. |
||
| 84 | * |
||
| 85 | * The data in this request has data for all 9 challenge mode maps (currently). The map field includes the current |
||
| 86 | * medal times for each dungeon. Inside each ladder we provide data about each character that was part of each run. |
||
| 87 | * The character data includes the current cached spec of the character while the member field includes the spec of |
||
| 88 | * the character during the challenge mode run. |
||
| 89 | * |
||
| 90 | * @param string $realm Realm's name being requested |
||
| 91 | * @param array $options Options |
||
| 92 | * |
||
| 93 | * @return Illuminate\Support\Collection api response |
||
| 94 | */ |
||
| 95 | public function getRealmLeaderboard($realm, array $options = []) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get region leaderboards. |
||
| 102 | * |
||
| 103 | * The region leaderboard has the exact same data format as the realm leaderboards except there is no realm field. |
||
| 104 | * It is simply the top 100 results gathered for each map for all of the available realm leaderboards in a region. |
||
| 105 | * |
||
| 106 | * @param array $options Options |
||
| 107 | * |
||
| 108 | * @return Illuminate\Support\Collection api response |
||
| 109 | */ |
||
| 110 | public function getRegionLeaderboard(array $options = []) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get character information. |
||
| 117 | * |
||
| 118 | * The Character Profile API is the primary way to access character information. This Character Profile API can be |
||
| 119 | * used to fetch a single character at a time through an HTTP GET request to a URL describing the character profile |
||
| 120 | * resource. By default, a basic dataset will be returned and with each request and zero or more additional fields |
||
| 121 | * can be retrieved. To access this API, craft a resource URL pointing to the character who's information is to be |
||
| 122 | * retrieved |
||
| 123 | * |
||
| 124 | * @param string $realm Character's realm. Can be provided as the proper realm name or the normalized realm name |
||
| 125 | * @param string $characterName Name of the character you want to retrieve |
||
| 126 | * @param array $options Options |
||
| 127 | * |
||
| 128 | * @return Illuminate\Support\Collection api response |
||
| 129 | */ |
||
| 130 | public function getCharacter($realm, $characterName, array $options = []) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get guild profile. |
||
| 137 | * |
||
| 138 | * The guild profile API is the primary way to access guild information. This guild profile API can be used to fetch |
||
| 139 | * a single guild at a time through an HTTP GET request to a url describing the guild profile resource. By default, |
||
| 140 | * a basic dataset will be returned and with each request and zero or more additional fields can be retrieved. |
||
| 141 | * |
||
| 142 | * There are no required query string parameters when accessing this resource, although the fields query string |
||
| 143 | * parameter can optionally be passed to indicate that one or more of the optional datasets is to be retrieved. |
||
| 144 | * Those additional fields are listed in the method titled "Optional Fields". |
||
| 145 | * |
||
| 146 | * @param string $realm Realm the guild lives on |
||
| 147 | * @param string $guildName Name of the guild being retrieved |
||
| 148 | * @param array $options Options |
||
| 149 | * |
||
| 150 | * @return Illuminate\Support\Collection api response |
||
| 151 | */ |
||
| 152 | public function getGuild($realm, $guildName, array $options = []) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Get guild members. |
||
| 159 | * |
||
| 160 | * This provides a list of characters currently in the guild Roster. |
||
| 161 | * This is a wrapper function for the getGuild data function for easier access. |
||
| 162 | * |
||
| 163 | * @param string $realm Realm the guild lives on |
||
| 164 | * @param string $guildName Name of the guild being retrieved |
||
| 165 | * @param array $options Options |
||
| 166 | * |
||
| 167 | * @return Illuminate\Support\Collection api response |
||
| 168 | */ |
||
| 169 | public function getGuildMembers($realm, $guildName, array $options = []) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Get item information by id. |
||
| 184 | * |
||
| 185 | * The item API provides detailed item information. This includes item set information if this item is part of a set. |
||
| 186 | * |
||
| 187 | * @param int $itemId Id of the item being retrieved |
||
| 188 | * @param array $options Options |
||
| 189 | * |
||
| 190 | * @return Illuminate\Support\Collection api response |
||
| 191 | */ |
||
| 192 | public function getItem($itemId, array $options = []) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Get set information by id. |
||
| 199 | * |
||
| 200 | * The item API provides detailed item information. This includes item set information if this item is part of a set. |
||
| 201 | * |
||
| 202 | * @param int $setId Id of the set being requested |
||
| 203 | * @param array $options Options |
||
| 204 | * |
||
| 205 | * @return Illuminate\Support\Collection api response |
||
| 206 | */ |
||
| 207 | public function getItemSet($setId, array $options = []) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Get mount master list. |
||
| 214 | * |
||
| 215 | * A list of all supported mounts |
||
| 216 | * |
||
| 217 | * @param array $options Options |
||
| 218 | * |
||
| 219 | * @return Illuminate\Support\Collection api response |
||
| 220 | */ |
||
| 221 | public function getMountMasterList(array $options = []) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Get pet lists. |
||
| 228 | * |
||
| 229 | * A list of all supported battle and vanity pets |
||
| 230 | * |
||
| 231 | * @param array $options Options |
||
| 232 | * |
||
| 233 | * @return Illuminate\Support\Collection api response |
||
| 234 | */ |
||
| 235 | public function getPetList(array $options = []) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Get pet ability information by id. |
||
| 242 | * |
||
| 243 | * This provides data about a individual battle pet ability ID. We do not provide the tooltip for the ability yet. |
||
| 244 | * We are working on a better way to provide this since it depends on your pet's species, level and quality rolls. |
||
| 245 | * |
||
| 246 | * @param int $abilityId Id of the ability you want to retrieve |
||
| 247 | * @param array $options Options |
||
| 248 | * |
||
| 249 | * @return Illuminate\Support\Collection api response |
||
| 250 | */ |
||
| 251 | public function getPetAbility($abilityId, array $options = []) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Get pet species information by id. |
||
| 258 | * |
||
| 259 | * This provides the data about an individual pet species. The species IDs can be found your character profile |
||
| 260 | * using the options pets field. Each species also has data about what it's 6 abilities are. |
||
| 261 | * |
||
| 262 | * @param int $speciesId The species you want to retrieve |
||
| 263 | * @param array $options Options |
||
| 264 | * |
||
| 265 | * @return Illuminate\Support\Collection api response |
||
| 266 | */ |
||
| 267 | public function getPetSpecies($speciesId, array $options = []) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Get pet stats by species id. |
||
| 274 | * |
||
| 275 | * Retrieve detailed information about a given species of pet |
||
| 276 | * |
||
| 277 | * @param int $speciesId Pet's species id. This can be found by querying a users' list of pets via the Character Profile API |
||
| 278 | * @param array $options Options |
||
| 279 | * |
||
| 280 | * @return Illuminate\Support\Collection api response |
||
| 281 | */ |
||
| 282 | public function getPetStats($speciesId, array $options = []) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Get leaderboards. |
||
| 289 | * |
||
| 290 | * The Leaderboard API endpoint provides leaderboard information for the 2v2, 3v3, 5v5 and Rated Battleground |
||
| 291 | * leaderboards. |
||
| 292 | * |
||
| 293 | * @param int $bracket Type of leaderboard you want to retrieve. Example: 2v2, 3v3, 5v5, and rbg |
||
| 294 | * @param array $options Options |
||
| 295 | * |
||
| 296 | * @return Illuminate\Support\Collection api response |
||
| 297 | */ |
||
| 298 | public function getLeaderboards($bracket, array $options = []) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get quest information by id. |
||
| 305 | * |
||
| 306 | * Retrieve metadata for a given quest. |
||
| 307 | * |
||
| 308 | * @param int $questId Id of the quest you want to retrieve |
||
| 309 | * @param array $options Options |
||
| 310 | * |
||
| 311 | * @return Illuminate\Support\Collection api response |
||
| 312 | */ |
||
| 313 | public function getQuest($questId, array $options = []) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Get realm status. |
||
| 320 | * |
||
| 321 | * The realm status API allows developers to retrieve realm status information. This information is limited to |
||
| 322 | * whether or not the realm is up, the type and state of the realm, the current population, and the status of the |
||
| 323 | * two world PvP zones |
||
| 324 | * |
||
| 325 | * @param array $options Options |
||
| 326 | * |
||
| 327 | * @return Illuminate\Support\Collection api response |
||
| 328 | */ |
||
| 329 | public function getRealmStatus(array $options = []) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Get recipe information by id. |
||
| 336 | * |
||
| 337 | * The recipe API provides basic recipe information |
||
| 338 | * |
||
| 339 | * @param int $recipeId Id for the desired recipe |
||
| 340 | * @param array $options Options |
||
| 341 | * |
||
| 342 | * @return Illuminate\Support\Collection api response |
||
| 343 | */ |
||
| 344 | public function getRecipe($recipeId, array $options = []) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get spell information by id. |
||
| 351 | * |
||
| 352 | * The spell API provides some information about spells |
||
| 353 | * |
||
| 354 | * @param int $spellId Id of the desired spell |
||
| 355 | * @param array $options Options |
||
| 356 | * |
||
| 357 | * @return Illuminate\Support\Collection api response |
||
| 358 | */ |
||
| 359 | public function getSpell($spellId, array $options = []) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get zone master list. |
||
| 366 | * |
||
| 367 | * A list of all supported zones and their bosses. A 'zone' in this context should be considered a dungeon, or a |
||
| 368 | * raid, not a zone as in a world zone. A 'boss' in this context should be considered a boss encounter, which may |
||
| 369 | * include more than one NPC. |
||
| 370 | * |
||
| 371 | * @param array $options Options |
||
| 372 | * |
||
| 373 | * @return Illuminate\Support\Collection api response |
||
| 374 | */ |
||
| 375 | public function getZonesMasterList(array $options = []) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Get zone information by id. |
||
| 382 | * |
||
| 383 | * The Zone API provides some information about zones. |
||
| 384 | * |
||
| 385 | * @param int $zoneId Id of the zone you want to retrieve |
||
| 386 | * @param array $options Options |
||
| 387 | * |
||
| 388 | * @return Illuminate\Support\Collection api response |
||
| 389 | */ |
||
| 390 | public function getZone($zoneId, array $options = []) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Get data battlegroups. |
||
| 397 | * |
||
| 398 | * The battlegroups data API provides the list of battlegroups for this region. Please note the trailing '/' on this URL |
||
| 399 | * |
||
| 400 | * @param array $options Options |
||
| 401 | * |
||
| 402 | * @return Illuminate\Support\Collection api response |
||
| 403 | */ |
||
| 404 | public function getDataBattlegroups(array $options = []) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Get data character races. |
||
| 411 | * |
||
| 412 | * The character races data API provides a list of each race and their associated faction, name, unique ID, and skin |
||
| 413 | * |
||
| 414 | * @param array $options Options |
||
| 415 | * |
||
| 416 | * @return Illuminate\Support\Collection api response |
||
| 417 | */ |
||
| 418 | public function getDataCharacterRaces(array $options = []) |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Get data character classes. |
||
| 425 | * |
||
| 426 | * The character classes data API provides a list of character classes |
||
| 427 | * |
||
| 428 | * @param array $options Options |
||
| 429 | * |
||
| 430 | * @return Illuminate\Support\Collection api response |
||
| 431 | */ |
||
| 432 | public function getDataCharacterClasses(array $options = []) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get data character achievements. |
||
| 439 | * |
||
| 440 | * The character achievements data API provides a list of all of the achievements that characters can earn as well |
||
| 441 | * as the category structure and hierarchy |
||
| 442 | * |
||
| 443 | * @param array $options Options |
||
| 444 | * |
||
| 445 | * @return Illuminate\Support\Collection api response |
||
| 446 | */ |
||
| 447 | public function getDataCharacterAchievements(array $options = []) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Get data guild rewards. |
||
| 454 | * |
||
| 455 | * The guild rewards data API provides a list of all guild rewards |
||
| 456 | * |
||
| 457 | * @param array $options Options |
||
| 458 | * |
||
| 459 | * @return Illuminate\Support\Collection api response |
||
| 460 | */ |
||
| 461 | public function getDataGuildRewards(array $options = []) |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Get data guild perks. |
||
| 468 | * |
||
| 469 | * The guild perks data API provides a list of all guild perks |
||
| 470 | * |
||
| 471 | * @param array $options Options |
||
| 472 | * |
||
| 473 | * @return Illuminate\Support\Collection api response |
||
| 474 | */ |
||
| 475 | public function getDataGuildPerks(array $options = []) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Get data guild achievements. |
||
| 482 | * |
||
| 483 | * The guild achievements data API provides a list of all of the achievements that guilds can earn as well as the |
||
| 484 | * category structure and hierarchy |
||
| 485 | * |
||
| 486 | * @param array $options Options |
||
| 487 | * |
||
| 488 | * @return Illuminate\Support\Collection api response |
||
| 489 | */ |
||
| 490 | public function getDataGuildAchievements(array $options = []) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Get data item classes. |
||
| 497 | * |
||
| 498 | * The item classes data API provides a list of item classes |
||
| 499 | * |
||
| 500 | * @param array $options Options |
||
| 501 | * |
||
| 502 | * @return Illuminate\Support\Collection api response |
||
| 503 | */ |
||
| 504 | public function getDataItemClasses(array $options = []) |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Get data talents. |
||
| 511 | * |
||
| 512 | * The talents data API provides a list of talents, specs and glyphs for each class |
||
| 513 | * |
||
| 514 | * @param array $options Options |
||
| 515 | * |
||
| 516 | * @return Illuminate\Support\Collection api response |
||
| 517 | */ |
||
| 518 | public function getDataTalents(array $options = []) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Get data pet types. |
||
| 525 | * |
||
| 526 | * The different bat pet types (including what they are strong and weak against) |
||
| 527 | * |
||
| 528 | * @param array $options Options |
||
| 529 | * |
||
| 530 | * @return Illuminate\Support\Collection api response |
||
| 531 | */ |
||
| 532 | public function getDataPetTypes(array $options = []) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Get profile characters. |
||
| 539 | * |
||
| 540 | * This provides data about the current logged in OAuth user's - or the given user - WoW profile |
||
| 541 | * |
||
| 542 | * @param array $options Options |
||
| 543 | * |
||
| 544 | * @return Illuminate\Support\Collection api response |
||
| 545 | */ |
||
| 546 | public function getProfileCharacters(array $options = []) |
||
| 570 | } |
||
| 571 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: