Completed
Pull Request — master (#11)
by Dániel
01:23
created

WowService::getGuildMembers()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 34
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 16
nc 5
nop 3
1
<?php
2
3
namespace Xklusive\BattlenetApi\Services;
4
5
use Xklusive\BattlenetApi\BattlenetHttpClient;
6
use Illuminate\Support\Collection;
7
8
/**
9
 * @author Guillaume Meheust <[email protected]>
10
 */
11
class WowService extends BattlenetHttpClient
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected $gameParam = '/wow';
17
18
    /**
19
     * Get achievement information by id.
20
     *
21
     * This provides data about an individual achievement
22
     *
23
     * @param int   $achievementId Id of the achievement to retrieve
24
     * @param array $options       Options
25
     *
26
     * @return Illuminate\Support\Collection api response
27
     */
28
    public function getAchievement($achievementId, array $options = [])
29
    {
30
        return $this->cache('/achievement/'.(int) $achievementId, $options, __FUNCTION__);
31
    }
32
33
    /**
34
     * Get auction data.
35
     *
36
     * Auction APIs currently provide rolling batches of data about current auctions. Fetching auction dumps is a two
37
     * step process that involves checking a per-realm index file to determine if a recent dump has been generated and
38
     * then fetching the most recently generated dump file if necessary.
39
     *
40
     * This API resource provides a per-realm list of recently generated auction house data dumps
41
     *
42
     * @param string $realm   Realm being requested
43
     * @param array  $options Options
44
     *
45
     * @return Illuminate\Support\Collection api response
46
     */
47
    public function getAuctionDataStatus($realm, array $options = [])
48
    {
49
        return $this->cache('/auction/data/'.(string) $realm, $options, __FUNCTION__);
50
    }
51
52
    /**
53
     * Get boss master list.
54
     *
55
     * A list of all supported bosses. A 'boss' in this context should be considered a boss encounter, which may include
56
     * more than one NPC.
57
     *
58
     * @param array $options Options
59
     *
60
     * @return Illuminate\Support\Collection api response
61
     */
62
    public function getBossMasterList(array $options = [])
63
    {
64
        return $this->cache('/boss/', $options, __FUNCTION__);
65
    }
66
67
    /**
68
     * Get boss information by id.
69
     *
70
     * The boss API provides information about bosses. A 'boss' in this context should be considered a boss encounter,
71
     * which may include more than one NPC.
72
     *
73
     * @param int   $bossId  Id of the boss you want to retrieve
74
     * @param array $options Options
75
     *
76
     * @return Illuminate\Support\Collection api response
77
     */
78
    public function getBoss($bossId, array $options = [])
79
    {
80
        return $this->cache('/boss/'.(int) $bossId, $options, __FUNCTION__);
81
    }
82
83
    /**
84
     * Get realm leaderboards.
85
     *
86
     * The data in this request has data for all 9 challenge mode maps (currently). The map field includes the current
87
     * medal times for each dungeon. Inside each ladder we provide data about each character that was part of each run.
88
     * The character data includes the current cached spec of the character while the member field includes the spec of
89
     * the character during the challenge mode run.
90
     *
91
     * @param string $realm   Realm's name being requested
92
     * @param array  $options Options
93
     *
94
     * @return Illuminate\Support\Collection api response
95
     */
96
    public function getRealmLeaderboard($realm, array $options = [])
97
    {
98
        return $this->cache('/challenge/'.(string) $realm, $options, __FUNCTION__);
99
    }
100
101
    /**
102
     * Get region leaderboards.
103
     *
104
     * The region leaderboard has the exact same data format as the realm leaderboards except there is no realm field.
105
     * It is simply the top 100 results gathered for each map for all of the available realm leaderboards in a region.
106
     *
107
     * @param array $options Options
108
     *
109
     * @return Illuminate\Support\Collection api response
110
     */
111
    public function getRegionLeaderboard(array $options = [])
112
    {
113
        return $this->cache('/challenge/region', $options, __FUNCTION__);
114
    }
115
116
    /**
117
     * Get character information.
118
     *
119
     * The Character Profile API is the primary way to access character information. This Character Profile API can be
120
     * used to fetch a single character at a time through an HTTP GET request to a URL describing the character profile
121
     * resource. By default, a basic dataset will be returned and with each request and zero or more additional fields
122
     * can be retrieved. To access this API, craft a resource URL pointing to the character who's information is to be
123
     * retrieved
124
     *
125
     * @param string $realm         Character's realm. Can be provided as the proper realm name or the normalized realm name
126
     * @param string $characterName Name of the character you want to retrieve
127
     * @param array  $options       Options
128
     *
129
     * @return Illuminate\Support\Collection api response
130
     */
131
    public function getCharacter($realm, $characterName, array $options = [])
132
    {
133
        return $this->cache('/character/'.(string) $realm.'/'.(string) $characterName, $options, __FUNCTION__);
134
    }
135
136
    /**
137
     * Get guild profile.
138
     *
139
     * The guild profile API is the primary way to access guild information. This guild profile API can be used to fetch
140
     * a single guild at a time through an HTTP GET request to a url describing the guild profile resource. By default,
141
     * a basic dataset will be returned and with each request and zero or more additional fields can be retrieved.
142
     *
143
     * There are no required query string parameters when accessing this resource, although the fields query string
144
     * parameter can optionally be passed to indicate that one or more of the optional datasets is to be retrieved.
145
     * Those additional fields are listed in the method titled "Optional Fields".
146
     *
147
     * @param string $realm     Realm the guild lives on
148
     * @param string $guildName Name of the guild being retrieved
149
     * @param array  $options   Options
150
     *
151
     * @return Illuminate\Support\Collection api response
152
     */
153
    public function getGuild($realm, $guildName, array $options = [])
154
    {
155
        return $this->cache('/guild/'.(string) $realm.'/'.(string) $guildName, $options, __FUNCTION__);
156
    }
157
158
    /**
159
     * Get guild members.
160
     *
161
     * This provides a list of characters currently in the guild Roster.
162
     * This is a wrapper function for the getGuild data function for easier access.
163
     *
164
     * @param string $realm     Realm the guild lives on
165
     * @param string $guildName Name of the guild being retrieved
166
     * @param array  $options   Options
167
     *
168
     * @return Illuminate\Support\Collection api response
169
     */
170
    public function getGuildMembers($realm, $guildName, array $options = [])
171
    {
172
        $options = Collection::wrap($options);
173
174
        if ($options->has('query')) {
175
            $query = Collection::wrap($options->get('query'));
176
            $fields = Collection::wrap($query->get('fields'));
177
178
            if ($fields->isEmpty()) {
179
                // The options doesn't contain a fields section which is required for this query.
180
                // Lets add one with the default value 'members'
181
                $query->put('fields', 'members');
182
            }
183
184
            if ($fields->contains('members') === FALSE) {
185
                // The options does contain a fileds element but 'members' is not part of it
186
                // Lets add one 'members' to the list.
187
                $fields->push('members');
188
                $query->put('fields', $fields->implode(','));
189
            }
190
191
            $options->put('query', $query);
192
193
            // We already have everything we need, lets call the getGuild function to proceed
194
            return $this->getGuild($realm, $guildName, $options->toArray());
195
        }
196
197
        $query = collect();
198
        $query->put('fields','members');
199
200
        $options->put('query', $query);
201
202
        return $this->getGuild($realm, $guildName, $options->toArray());
203
    }
204
205
    /**
206
     * Get item information by id.
207
     *
208
     * The item API provides detailed item information. This includes item set information if this item is part of a set.
209
     *
210
     * @param int   $itemId  Id of the item being retrieved
211
     * @param array $options Options
212
     *
213
     * @return Illuminate\Support\Collection api response
214
     */
215
    public function getItem($itemId, array $options = [])
216
    {
217
        return $this->cache('/item/'.(int) $itemId, $options, __FUNCTION__);
218
    }
219
220
    /**
221
     * Get set information by id.
222
     *
223
     * The item API provides detailed item information. This includes item set information if this item is part of a set.
224
     *
225
     * @param int   $setId   Id of the set being requested
226
     * @param array $options Options
227
     *
228
     * @return Illuminate\Support\Collection api response
229
     */
230
    public function getItemSet($setId, array $options = [])
231
    {
232
        return $this->cache('/item/set/'.(int) $setId, $options, __FUNCTION__);
233
    }
234
235
    /**
236
     * Get mount master list.
237
     *
238
     * A list of all supported mounts
239
     *
240
     * @param array $options Options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
241
     *
242
     * @return Illuminate\Support\Collection api response
243
     */
244
    public function getMountMasterList()
245
    {
246
        return collect();
247
    }
248
249
    /**
250
     * Get pet lists.
251
     *
252
     * A list of all supported battle and vanity pets
253
     *
254
     * @param array $options Options
255
     *
256
     * @return Illuminate\Support\Collection api response
257
     */
258
    public function getPetList(array $options = [])
259
    {
260
        return $this->cache('/pet/', $options, __FUNCTION__);
261
    }
262
263
    /**
264
     * Get pet ability information by id.
265
     *
266
     * This provides data about a individual battle pet ability ID. We do not provide the tooltip for the ability yet.
267
     * We are working on a better way to provide this since it depends on your pet's species, level and quality rolls.
268
     *
269
     * @param int   $abilityId Id of the ability you want to retrieve
270
     * @param array $options   Options
271
     *
272
     * @return Illuminate\Support\Collection api response
273
     */
274
    public function getPetAbility($abilityId, array $options = [])
275
    {
276
        return $this->cache('/pet/ability/'.(int) $abilityId, $options, __FUNCTION__);
277
    }
278
279
    /**
280
     * Get pet species information by id.
281
     *
282
     * This provides the data about an individual pet species. The species IDs can be found your character profile
283
     * using the options pets field. Each species also has data about what it's 6 abilities are.
284
     *
285
     * @param int   $speciesId The species you want to retrieve
286
     * @param array $options   Options
287
     *
288
     * @return Illuminate\Support\Collection api response
289
     */
290
    public function getPetSpecies($speciesId, array $options = [])
291
    {
292
        return $this->cache('/pet/species/'.(int) $speciesId, $options, __FUNCTION__);
293
    }
294
295
    /**
296
     * Get pet stats by species id.
297
     *
298
     * Retrieve detailed information about a given species of pet
299
     *
300
     * @param int   $speciesId Pet's species id. This can be found by querying a users' list of pets via the Character Profile API
301
     * @param array $options   Options
302
     *
303
     * @return Illuminate\Support\Collection api response
304
     */
305
    public function getPetStats($speciesId, array $options = [])
306
    {
307
        $options = collect($options); // Create a collection from the options, easier to work with.
308
309
        foreach ($options as $key => $option) {
310
            if (in_array($key, ['level', 'breedId', 'qualityId'])) {
311
                // We have some valid options for this query, lets add them to the query options
312
                if ($options->has('query')) {
313
                    // We already have some query options lets add the new ones to the list.
314
                    $options->get('query')->put($key, $option);
315
                } else {
316
                    // We don't have any query options. Create a new collection and the first option to it.
317
                    $options->put('query', collect([$key => $option]));
318
                }
319
            }
320
        }
321
322
        return $this->cache('/pet/stats/'.(int) $speciesId, $options->toArray(), __FUNCTION__);
323
    }
324
325
    /**
326
     * Get leaderboards.
327
     *
328
     * The Leaderboard API endpoint provides leaderboard information for the 2v2, 3v3, 5v5 and Rated Battleground
329
     * leaderboards.
330
     *
331
     * @param int   $bracket Type of leaderboard you want to retrieve. Example: 2v2, 3v3, 5v5, and rbg
332
     * @param array $options Options
333
     *
334
     * @return Illuminate\Support\Collection api response
335
     */
336
    public function getLeaderboards($bracket, array $options = [])
337
    {
338
        return $this->cache('/leaderboard/'.(string) $bracket, $options, __FUNCTION__);
339
    }
340
341
    /**
342
     * Get quest information by id.
343
     *
344
     * Retrieve metadata for a given quest.
345
     *
346
     * @param int   $questId Id of the quest you want to retrieve
347
     * @param array $options Options
348
     *
349
     * @return Illuminate\Support\Collection api response
350
     */
351
    public function getQuest($questId, array $options = [])
352
    {
353
        return $this->cache('/quest/'.(int) $questId, $options, __FUNCTION__);
354
    }
355
356
    /**
357
     * Get realm status.
358
     *
359
     * The realm status API allows developers to retrieve realm status information. This information is limited to
360
     * whether or not the realm is up, the type and state of the realm, the current population, and the status of the
361
     * two world PvP zones
362
     *
363
     * @param array $options Options
364
     *
365
     * @return Illuminate\Support\Collection api response
366
     */
367
    public function getRealmStatus(array $options = [])
368
    {
369
        return $this->cache('/realm/status', $options, __FUNCTION__);
370
    }
371
372
    /**
373
     * Get recipe information by id.
374
     *
375
     * The recipe API provides basic recipe information
376
     *
377
     * @param int   $recipeId Id for the desired recipe
378
     * @param array $options  Options
379
     *
380
     * @return Illuminate\Support\Collection api response
381
     */
382
    public function getRecipe($recipeId, array $options = [])
383
    {
384
        return $this->cache('/recipe/'.(int) $recipeId, $options, __FUNCTION__);
385
    }
386
387
    /**
388
     * Get spell information by id.
389
     *
390
     * The spell API provides some information about spells
391
     *
392
     * @param int   $spellId Id of the desired spell
393
     * @param array $options Options
394
     *
395
     * @return Illuminate\Support\Collection api response
396
     */
397
    public function getSpell($spellId, array $options = [])
398
    {
399
        return $this->cache('/spell/'.(int) $spellId, $options, __FUNCTION__);
400
    }
401
402
    /**
403
     * Get zone master list.
404
     *
405
     * A list of all supported zones and their bosses. A 'zone' in this context should be considered a dungeon, or a
406
     * raid, not a zone as in a world zone. A 'boss' in this context should be considered a boss encounter, which may
407
     * include more than one NPC.
408
     *
409
     * @param array $options Options
410
     *
411
     * @return Illuminate\Support\Collection api response
412
     */
413
    public function getZonesMasterList(array $options = [])
414
    {
415
        return $this->cache('/zone/', $options, __FUNCTION__);
416
    }
417
418
    /**
419
     * Get zone information by id.
420
     *
421
     * The Zone API provides some information about zones.
422
     *
423
     * @param int   $zoneId  Id of the zone you want to retrieve
424
     * @param array $options Options
425
     *
426
     * @return Illuminate\Support\Collection api response
427
     */
428
    public function getZone($zoneId, array $options = [])
429
    {
430
        return $this->cache('/zone/'.(int) $zoneId, $options, __FUNCTION__);
431
    }
432
433
    /**
434
     * Get data battlegroups.
435
     *
436
     * The battlegroups data API provides the list of battlegroups for this region. Please note the trailing '/' on this URL
437
     *
438
     * @param array $options Options
439
     *
440
     * @return Illuminate\Support\Collection api response
441
     */
442
    public function getDataBattlegroups(array $options = [])
443
    {
444
        return $this->cache('/data/battlegroups/', $options, __FUNCTION__);
445
    }
446
447
    /**
448
     * Get data character races.
449
     *
450
     * The character races data API provides a list of each race and their associated faction, name, unique ID, and skin
451
     *
452
     * @param array $options Options
453
     *
454
     * @return Illuminate\Support\Collection api response
455
     */
456
    public function getDataCharacterRaces(array $options = [])
457
    {
458
        return $this->cache('/data/character/races', $options, __FUNCTION__);
459
    }
460
461
    /**
462
     * Get data character classes.
463
     *
464
     * The character classes data API provides a list of character classes
465
     *
466
     * @param array $options Options
467
     *
468
     * @return Illuminate\Support\Collection api response
469
     */
470
    public function getDataCharacterClasses(array $options = [])
471
    {
472
        return $this->cache('/data/character/classes', $options, __FUNCTION__);
473
    }
474
475
    /**
476
     * Get data character achievements.
477
     *
478
     * The character achievements data API provides a list of all of the achievements that characters can earn as well
479
     * as the category structure and hierarchy
480
     *
481
     * @param array $options Options
482
     *
483
     * @return Illuminate\Support\Collection api response
484
     */
485
    public function getDataCharacterAchievements(array $options = [])
486
    {
487
        return $this->cache('/data/character/achievements', $options, __FUNCTION__);
488
    }
489
490
    /**
491
     * Get data guild rewards.
492
     *
493
     * The guild rewards data API provides a list of all guild rewards
494
     *
495
     * @param array $options Options
496
     *
497
     * @return Illuminate\Support\Collection api response
498
     */
499
    public function getDataGuildRewards(array $options = [])
500
    {
501
        return $this->cache('/data/guild/rewards', $options, __FUNCTION__);
502
    }
503
504
    /**
505
     * Get data guild perks.
506
     *
507
     * The guild perks data API provides a list of all guild perks
508
     *
509
     * @param array $options Options
510
     *
511
     * @return Illuminate\Support\Collection api response
512
     */
513
    public function getDataGuildPerks(array $options = [])
514
    {
515
        return $this->cache('/data/guild/perks', $options, __FUNCTION__);
516
    }
517
518
    /**
519
     * Get data guild achievements.
520
     *
521
     * The guild achievements data API provides a list of all of the achievements that guilds can earn as well as the
522
     * category structure and hierarchy
523
     *
524
     * @param array $options Options
525
     *
526
     * @return Illuminate\Support\Collection api response
527
     */
528
    public function getDataGuildAchievements(array $options = [])
529
    {
530
        return $this->cache('/data/guild/achievements', $options, __FUNCTION__);
531
    }
532
533
    /**
534
     * Get data item classes.
535
     *
536
     * The item classes data API provides a list of item classes
537
     *
538
     * @param array $options Options
539
     *
540
     * @return Illuminate\Support\Collection api response
541
     */
542
    public function getDataItemClasses(array $options = [])
543
    {
544
        return $this->cache('/data/item/classes', $options, __FUNCTION__);
545
    }
546
547
    /**
548
     * Get data talents.
549
     *
550
     * The talents data API provides a list of talents, specs and glyphs for each class
551
     *
552
     * @param array $options Options
553
     *
554
     * @return Illuminate\Support\Collection api response
555
     */
556
    public function getDataTalents(array $options = [])
557
    {
558
        return $this->cache('/data/talents', $options, __FUNCTION__);
559
    }
560
561
    /**
562
     * Get data pet types.
563
     *
564
     * The different bat pet types (including what they are strong and weak against)
565
     *
566
     * @param array $options Options
567
     *
568
     * @return null|\Xklusive\BattlenetApi\Collection api response
569
     */
570
    public function getDataPetTypes(array $options = [])
571
    {
572
        return $this->cache('/data/pet/types', $options, __FUNCTION__);
573
    }
574
575
    /**
576
     * Get profile characters.
577
     *
578
     * This provides data about the current logged in OAuth user's - or the given user - WoW profile
579
     *
580
     * @param array $options Options
581
     *
582
     * @return Illuminate\Support\Collection api response
583
     */
584
    public function getProfileCharacters(array $options = [])
585
    {
586
        $access_token = array_key_exists('access_token', $options)
587
                                ? $options['access_token']
588
                                : auth()->user()->bnet_token;
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
589
590
        $access_scope = array_key_exists('access_scope', $options)
591
                                ? $options['access_scope']
592
                                : auth()->user()->bnet_scope;
593
594
        $user_id = array_key_exists('user_id', $options)
595
                                ? $options['user_id']
596
                                : auth()->user()->id;
597
598
        $options['query']['access_token'] = $access_token;
599
        $options['cache']['user_id'] = $user_id;
600
601
        if (strpos($access_scope, 'wow.profile') === false) {
602
            return;
603
        } else {
604
            return $this->cache('/user/characters', $options, __FUNCTION__);
605
        }
606
    }
607
}
608