Passed
Push — master ( 458136...010310 )
by Willy
01:57
created

CharacterProfileApi::getFeed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 15
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi;
4
5
use Kubinashi\BattlenetApi\Model\AuthenticationModel;
6
use Kubinashi\BattlenetApi\Model\Franchises;
7
use Kubinashi\BattlenetApi\Model\RequestModel;
8
use Kubinashi\BattlenetApi\Service\RequestService;
9
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\AchievementsValueObject;
10
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\AppearanceValueObject;
11
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\CharacterProfileValueObject;
12
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\EmblemValueObject;
13
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Feed\FeedObjectFactory;
14
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\GuildValueObject;
15
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\HunterPet\HunterPetSpecValueObject;
16
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\HunterPet\HunterPetValueObject;
17
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Mount\MountsValueObject;
18
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Mount\MountValueObject;
19
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Pet\PetStatValueObject;
20
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Pet\PetsValueObject;
21
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Pet\PetValueObject;
22
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\PetSlotsValueObject;
23
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Profession\ProfessionsValueObject;
24
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Profession\ProfessionValueObject;
25
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Progression\BossValueObject;
26
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Progression\ProgressionValueObject;
27
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Progression\RaidValueObject;
28
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Pvp\BracketValueObject;
29
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Pvp\PvpValueObject;
30
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\QuestsValueObject;
31
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\ReputationValueObject;
32
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Talent\SpecValueObject;
33
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Talent\TalentsValueObject;
34
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Talent\TalentValueObject;
35
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\TitleValueObject;
36
use Kubinashi\BattlenetApi\WorldOfWarcraft\Model\SpellValueObject;
37
38
/**
39
 * @author  Willy Reiche
40
 * @since   2017-07-19
41
 * @version 1.0
42
 */
43
class CharacterProfileApi{
44
    /**
45
     * @var AuthenticationModel
46
     */
47
    private $authenticationModel;
48
49
    /**
50
     * @var RequestService
51
     */
52
    private $requestService;
53
54
    /**
55
     * @var string
56
     */
57
    private $charName;
58
59
    /**
60
     * @var string
61
     */
62
    private $realm;
63
64
    /**
65
     * @param AuthenticationModel $authenticationModel
66
     * @param RequestService $requestService
67
     * @param string $charName
68
     * @param string $realm
69
     */
70 9
    public function __construct(
71
        AuthenticationModel $authenticationModel,
72
        RequestService $requestService,
73
        $charName,
74
        $realm
75
    ) {
76 9
        $this->requestService = $requestService;
77 9
        $this->authenticationModel = $authenticationModel;
78 9
        $this->charName = $charName;
79 9
        $this->realm = $realm;
80 9
    }
81
82
    /**
83
     * The basic character data
84
     *
85
     * @return CharacterProfileValueObject
86
     */
87 1
    public function getCharacterProfile()
88
    {
89 1
        $requestModel = $this->prepareRequestModel();
90 1
        $response = $this->requestService->doRequest($requestModel);
91 1
        $responseObject = json_decode($response);
92
93 1
        $characterProfile = new CharacterProfileValueObject(
94 1
            $responseObject->lastModified,
95 1
            $responseObject->name,
96 1
            $responseObject->realm,
97 1
            $responseObject->battlegroup,
98 1
            $responseObject->class,
99 1
            $responseObject->race,
100 1
            $responseObject->gender,
101 1
            $responseObject->level,
102 1
            $responseObject->achievementPoints,
103 1
            $responseObject->thumbnail,
104 1
            $responseObject->calcClass,
105 1
            $responseObject->faction,
106 1
            $responseObject->totalHonorableKills
107 1
        );
108
109 1
        return $characterProfile;
110
    }
111
112
    /**
113
     * A map of achievement data including completion timestamps and criteria information
114
     *
115
     * @return AchievementsValueObject
116
     */
117 1
    public function getAchievements()
118
    {
119 1
        $requestModel = $this->prepareRequestModel('achievements');
120 1
        $response = $this->requestService->doRequest($requestModel);
121 1
        $responseObject = json_decode($response);
122
123 1
        $achievements = new AchievementsValueObject(
124 1
            $responseObject->achievements->achievementsCompleted,
125 1
            $responseObject->achievements->achievementsCompletedTimestamp,
126 1
            $responseObject->achievements->criteria,
127 1
            $responseObject->achievements->criteriaQuantity,
128 1
            $responseObject->achievements->criteriaTimestamp,
129 1
            $responseObject->achievements->criteriaCreated
130 1
        );
131
132 1
        return $achievements;
133
    }
134
135
    /**
136
     * A map of a character's appearance settings such as which face texture they've selected and whether or not a healm is visible
137
     *
138
     * @return AppearanceValueObject
139
     */
140 1
    public function getAppearance()
141
    {
142 1
        $requestModel = $this->prepareRequestModel('appearance');
143 1
        $response = $this->requestService->doRequest($requestModel);
144 1
        $responseObject = json_decode($response);
145
146 1
        $appearance = new AppearanceValueObject(
147 1
            $responseObject->appearance->faceVariation,
148 1
            $responseObject->appearance->skinColor,
149 1
            $responseObject->appearance->hairVariation,
150 1
            $responseObject->appearance->hairColor,
151 1
            $responseObject->appearance->featureVariation,
152 1
            $responseObject->appearance->showHelm,
153 1
            $responseObject->appearance->showCloak,
154 1
            $responseObject->appearance->customDisplayOptions
155 1
        );
156
157 1
        return $appearance;
158
    }
159
160
    /**
161
     * The activity feed of the character
162
     * Based on the type you get a different Object to access
163
     * - Achievement = FeedAchievementValueObject
164
     * - Bosskill = FeedBosskillValueObject
165
     * - Loot = FeedLootValueObject
166
     *
167
     * @return array
168
     */
169 View Code Duplication
    public function getFeed()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
170
    {
171
        $requestModel = $this->prepareRequestModel('feed');
172
        $response = $this->requestService->doRequest($requestModel);
173
        $responseObject = json_decode($response);
174
175
        $feedObjectFactory = new FeedObjectFactory();
176
        $feedObj = [];
177
178
        foreach ($responseObject->feed as $feed) {
179
            $feedObj[] = $feedObjectFactory->getFeedObject($feed);
180
        }
181
182
        return $feedObj;
183
    }
184
185
    /**
186
     * A summary of the guild that the character belongs to
187
     *
188
     * @return GuildValueObject
189
     */
190 1
    public function getGuild()
191
    {
192 1
        $requestModel = $this->prepareRequestModel('guild');
193 1
        $response = $this->requestService->doRequest($requestModel);
194 1
        $responseObject = json_decode($response);
195
196 1
        $emblemValueObject = $this->prepareEmblem($responseObject->guild->emblem);
197
198 1
        $guild = new GuildValueObject(
199 1
            $responseObject->guild->name,
200 1
            $responseObject->guild->realm,
201 1
            $responseObject->guild->battlegroup,
202 1
            $responseObject->guild->members,
203
            $emblemValueObject
204 1
        );
205
206 1
        return $guild;
207
    }
208
209
    /**
210
     * A list of all of the combat pets obtained by the character
211
     *
212
     * @return HunterPetValueObject[]
213
     */
214 1
    public function getHunterPets()
215
    {
216 1
        $requestModel = $this->prepareRequestModel('hunterPets');
217 1
        $response = $this->requestService->doRequest($requestModel);
218 1
        $responseObject = json_decode($response);
219
220 1
        return $this->prepareHunterPets($responseObject);
221
    }
222
223
    /**
224
     * A list of all of the mounts obtained by the character
225
     *
226
     * @return MountsValueObject
227
     */
228 1 View Code Duplication
    public function getMounts()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
229
    {
230 1
        $requestModel = $this->prepareRequestModel('mounts');
231 1
        $response = $this->requestService->doRequest($requestModel);
232 1
        $responseObject = json_decode($response);
233
234 1
        $collectedMounts = [];
235 1
        foreach ($responseObject->mounts->collected as $mount) {
236 1
            $collectedMounts[] = $this->prepareMountValueObject($mount);
237 1
        }
238
239 1
        $mounts = new MountsValueObject(
240 1
            $responseObject->mounts->numCollected,
241 1
            $responseObject->mounts->numNotCollected,
242
            $collectedMounts
243 1
        );
244
245 1
        return $mounts;
246
    }
247
248
    /**
249
     * A list of the battle pets obtained by the character
250
     *
251
     * @return PetsValueObject
252
     */
253 1 View Code Duplication
    public function getPets()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
254
    {
255 1
        $requestModel = $this->prepareRequestModel('pets');
256 1
        $response = $this->requestService->doRequest($requestModel);
257 1
        $responseObject = json_decode($response);
258
259 1
        $collectedPets = [];
260 1
        foreach ($responseObject->pets->collected as $pet) {
261 1
            $collectedPets[] = $this->preparePetValueObject($pet);
262 1
        }
263
264 1
        $pets = new PetsValueObject(
265 1
            $responseObject->pets->numCollected,
266 1
            $responseObject->pets->numNotCollected,
267
            $collectedPets
268 1
        );
269
270 1
        return $pets;
271
    }
272
273
    /**
274
     * Data about the current battle pet slots on this characters account
275
     *
276
     * @return PetSlotsValueObject[]
277
     */
278 View Code Duplication
    public function getPetSlots()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
279
    {
280
        $requestModel = $this->prepareRequestModel('petSlots');
281
        $response = $this->requestService->doRequest($requestModel);
282
        $responseObject = json_decode($response);
283
        $petSlots = [];
284
285
        foreach ($responseObject->petSlots as $petSlot) {
286
            $petSlots[] = new PetSlotsValueObject(
287
                $petSlot->slot,
288
                $petSlot->battlePetGuid,
289
                $petSlot->isEmpty,
290
                $petSlot->isLocked,
291
                $petSlot->abilities
292
            );
293
        }
294
295
        return $petSlots;
296
    }
297
298
    /**
299
     * A list of the character's professions. Does not include class professions
300
     *
301
     * @return ProfessionsValueObject
302
     */
303 1
    public function getProfessions()
304
    {
305 1
        $requestModel = $this->prepareRequestModel('professions');
306 1
        $response = $this->requestService->doRequest($requestModel);
307 1
        $responseObject = json_decode($response);
308
309 1
        $primaryProfessions = $this->prepareProfessionValueObject($responseObject->professions->primary);
310 1
        $secondaryProfessions = $this->prepareProfessionValueObject($responseObject->professions->secondary);
311
312 1
        $professions = new ProfessionsValueObject(
313 1
            $primaryProfessions,
314
            $secondaryProfessions
315 1
        );
316
317 1
        return $professions;
318
    }
319
320
    /**
321
     * A list of raids and bosses indicating raid progression and completeness
322
     *
323
     * @return ProgressionValueObject
324
     */
325 View Code Duplication
    public function getProgression()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
326
    {
327
        $requestModel = $this->prepareRequestModel('progression');
328
        $response = $this->requestService->doRequest($requestModel);
329
        $responseObject = json_decode($response);
330
331
        $raids = $this->prepareRaidValueObject($responseObject);
332
333
        $progression = new ProgressionValueObject(
334
            $raids
335
        );
336
337
        return $progression;
338
    }
339
340
    /**
341
     * A map of pvp information including arena team membership and rated battlegrounds information
342
     *
343
     * @return PvpValueObject
344
     */
345 View Code Duplication
    public function getPvp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
346
    {
347
        $requestModel = $this->prepareRequestModel('pvp');
348
        $response = $this->requestService->doRequest($requestModel);
349
        $responseObject = json_decode($response);
350
351
        $brackets = $this->prepareBracketValueObject($responseObject);
352
353
        $progression = new PvpValueObject(
354
            $brackets
355
        );
356
357
        return $progression;
358
    }
359
360
    /**
361
     * A list of quests completed by the character
362
     *
363
     * @return QuestsValueObject
364
     */
365 View Code Duplication
    public function getQuests()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
366
    {
367
        $requestModel = $this->prepareRequestModel('quests');
368
        $response = $this->requestService->doRequest($requestModel);
369
        $responseObject = json_decode($response);
370
371
        $quests = new QuestsValueObject(
372
            $responseObject->quests
373
        );
374
375
        return $quests;
376
    }
377
378
    /**
379
     * A list of the factions that the character has an associated reputation with
380
     *
381
     * @return ReputationValueObject[]
382
     */
383 View Code Duplication
    public function getReputation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
384
    {
385
        $requestModel = $this->prepareRequestModel('reputation');
386
        $response = $this->requestService->doRequest($requestModel);
387
        $responseObject = json_decode($response);
388
        $reputations = [];
389
390
        foreach ($responseObject->reputation as $reputation) {
391
            $reputations[] = new ReputationValueObject(
392
                $reputation->id,
393
                $reputation->name,
394
                $reputation->standing,
395
                $reputation->value,
396
                $reputation->max
397
            );
398
        }
399
400
        return $reputations;
401
    }
402
403
    /**
404
     * A list of talent structures
405
     *
406
     * @return TalentsValueObject[]
407
     */
408
    public function getTalents()
409
    {
410
        $requestModel = $this->prepareRequestModel('talents');
411
        $response = $this->requestService->doRequest($requestModel);
412
        $responseObject = json_decode($response);
413
        $talents = [];
414
415
        foreach ($responseObject->talents as $talent) {
416
            if (empty($talent->calcSpec)) {
417
                continue;
418
            }
419
420
            $selected = false;
421
            if (isset($talent->selected)) {
422
                $selected = true;
423
            }
424
425
            $talentsValueObject = $this->prepareTalentsValueObject($talent);
426
            $specValueObject = $this->prepareSpecValueObject($talent->spec);
427
428
            $talents[] = new TalentValueObject(
429
                $selected,
430
                $talentsValueObject,
431
                $specValueObject,
432
                $talent->calcTalent,
433
                $talent->calcSpec
434
            );
435
        }
436
437
        return $talents;
438
    }
439
440
    /**
441
     * A list of the titles obtained by the character including the currently selected title
442
     *
443
     * @return ReputationValueObject[]
444
     */
445 View Code Duplication
    public function getTitles()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
446
    {
447
        $requestModel = $this->prepareRequestModel('titles');
448
        $response = $this->requestService->doRequest($requestModel);
449
        $responseObject = json_decode($response);
450
        $titles = [];
451
452
        foreach ($responseObject->titles as $title) {
453
            $titles[] = new TitleValueObject(
454
                $title->id,
455
                $title->name
456
            );
457
        }
458
459
        return $titles;
460
    }
461
462
    /**
463
     * @param string $addition
464
     * @return RequestModel
465
     */
466 8
    private function prepareRequestModel($addition = '')
467
    {
468 8
        return new RequestModel(
469 8
            $this->authenticationModel->getRegion(),
470 8
            $this->authenticationModel->getApiKey(),
471 8
            $this->authenticationModel->getLocale(),
472 8
            [$this->realm, $this->charName],
473 8
            'character',
474 8
            Franchises::WORLD_OF_WARCRAFT,
475
            $addition
476 8
        );
477
    }
478
479
    /**
480
     * @param \StdClass $spec
481
     * @return HunterPetSpecValueObject
482
     */
483 1
    private function prepareHunterPetSpecValueObject(\StdClass $spec)
484
    {
485 1
        return new HunterPetSpecValueObject(
486 1
            $spec->name,
487 1
            $spec->role,
488 1
            $spec->backgroundImage,
489 1
            $spec->icon,
490 1
            $spec->description,
491 1
            $spec->order
492 1
        );
493
    }
494
495
    /**
496
     * @param array $professions
497
     *
498
     * @return array
499
     */
500 1
    private function prepareProfessionValueObject($professions) {
501 1
        $characterProfessions = [];
502
503 1
        foreach ($professions as $profession) {
504 1
            $characterProfessions[] = new ProfessionValueObject(
505 1
                $profession->id,
506 1
                $profession->name,
507 1
                $profession->icon,
508 1
                $profession->rank,
509 1
                $profession->max,
510 1
                $profession->recipes
511 1
            );
512 1
        }
513
514 1
        return $characterProfessions;
515
    }
516
517
    /**
518
     * @param \StdClass $emblem
519
     * @return EmblemValueObject
520
     */
521 1
    private function prepareEmblem($emblem)
522
    {
523 1
        return new EmblemValueObject (
524 1
            $emblem->icon,
525 1
            $emblem->iconColor,
526 1
            $emblem->iconColorId,
527 1
            $emblem->border,
528 1
            $emblem->borderColor,
529 1
            $emblem->borderColorId,
530 1
            $emblem->backgroundColor,
531 1
            $emblem->backgroundColorId
532 1
        );
533
    }
534
535
    /**
536
     * @param \StdClass $mount
537
     * @return MountValueObject
538
     */
539 1
    private function prepareMountValueObject(\StdClass $mount)
540
    {
541 1
        return new MountValueObject(
542 1
            $mount->name,
543 1
            $mount->spellId,
544 1
            $mount->creatureId,
545 1
            $mount->itemId,
546 1
            $mount->qualityId,
547 1
            $mount->icon,
548 1
            $mount->isGround,
549 1
            $mount->isFlying,
550 1
            $mount->isAquatic,
551 1
            $mount->isJumping
552 1
        );
553
    }
554
555
    /**
556
     * @param \StdClass $responseObject
557
     * @return HunterPetValueObject[]
558
     */
559 1
    private function prepareHunterPets(\StdClass $responseObject)
560
    {
561 1
        $hunterPets = [];
562 1
        foreach ($responseObject->hunterPets as $hunterPet) {
563 1
            $hunterPetSpecValueObject = null;
564 1
            if (isset($hunterPet->spec)) {
565 1
                $hunterPetSpecValueObject = $this->prepareHunterPetSpecValueObject($hunterPet->spec);
566 1
            }
567
568 1
            $hunterPets[] = new HunterPetValueObject(
569 1
                $hunterPet->name,
570 1
                $hunterPet->creature,
571 1
                $hunterPet->slot,
572 1
                $hunterPet->calcSpec,
573 1
                $hunterPet->familyId,
574 1
                $hunterPet->familyName,
575
                $hunterPetSpecValueObject
576 1
            );
577 1
        }
578
579 1
        return $hunterPets;
580
    }
581
582
    /**
583
     * @param \StdClass $pet
584
     * @return PetValueObject
585
     */
586 1
    private function preparePetValueObject($pet)
587
    {
588 1
        $petStatValueObject = $this->preparePetStatsValueObject($pet->stats);
589
590 1
        return new PetValueObject(
591 1
            $pet->name,
592 1
            $pet->spellId,
593 1
            $pet->creatureId,
594 1
            $pet->itemId,
595 1
            $pet->qualityId,
596 1
            $pet->icon,
597 1
            $petStatValueObject,
598 1
            $pet->battlePetGuid,
599 1
            $pet->isFavorite,
600 1
            $pet->isFirstAbilitySlotSelected,
601 1
            $pet->isSecondAbilitySlotSelected,
602 1
            $pet->isThirdAbilitySlotSelected,
603 1
            $pet->creatureName,
604 1
            $pet->canBattle
605 1
        );
606
    }
607
608
    /**
609
     * @param \StdClass $stats
610
     * @return PetStatValueObject
611
     */
612 1
    private function preparePetStatsValueObject($stats)
613
    {
614 1
        return new PetStatValueObject(
615 1
            $stats->speciesId,
616 1
            $stats->breedId,
617 1
            $stats->petQualityId,
618 1
            $stats->level,
619 1
            $stats->health,
620 1
            $stats->power,
621 1
            $stats->speed
622 1
        );
623
    }
624
625
    /**
626
     * @param \StdClass $raid
627
     * @return BossValueObject[]
628
     */
629
    private function prepareBossValueObject($raid)
630
    {
631
        $bosses = [];
632
        foreach ($raid->bosses as $boss) {
633
            $bosses[] = new BossValueObject(
634
                $boss->id,
635
                $boss->name,
636
                $boss->lfrKills,
637
                $boss->lfrTimestamp,
638
                $boss->normalKills,
639
                $boss->normalTimestamp,
640
                $boss->heroicKills,
641
                $boss->heroicTimestamp,
642
                $boss->mythicKills,
643
                $boss->mythicTimestamp
644
            );
645
        }
646
647
        return $bosses;
648
    }
649
650
    /**
651
     * @param \StdClass $responseObject
652
     * @return RaidValueObject[]
653
     */
654
    private function prepareRaidValueObject($responseObject)
655
    {
656
        $raids = [];
657
658
        foreach ($responseObject->progression->raids as $raid) {
659
            $bosses = $this->prepareBossValueObject($raid);
660
661
            $raids[] = new RaidValueObject(
662
                $raid->name,
663
                $raid->lfr,
664
                $raid->normal,
665
                $raid->heroic,
666
                $raid->mythic,
667
                $raid->id,
668
                $bosses
669
            );
670
        }
671
672
        return $raids;
673
    }
674
675
    /**
676
     * @param \StdClass $responseObject
677
     * @return BracketValueObject[]
678
     */
679
    private function prepareBracketValueObject($responseObject)
680
    {
681
        $brackets = [];
682
683
        foreach ($responseObject->pvp->brackets as $bracket) {
684
            $brackets[] = new BracketValueObject(
685
                $bracket->slug,
686
                $bracket->rating,
687
                $bracket->weeklyPlayed,
688
                $bracket->weeklyWon,
689
                $bracket->weeklyLost,
690
                $bracket->seasonPlayed,
691
                $bracket->seasonWon,
692
                $bracket->seasonLost
693
            );
694
        }
695
696
        return $brackets;
697
    }
698
699
    /**
700
     * @param $talent
701
     * @return TalentsValueObject[]
702
     */
703
    private function prepareTalentsValueObject($talent)
704
    {
705
        $talents = [];
706
        foreach ($talent->talents as $talent) {
707
            $cooldown = "";
708
            if (isset($talent->spell->cooldown)) {
709
                $cooldown = $talent->spell->cooldown;
710
            }
711
712
            $spell = new SpellValueObject(
713
                $talent->spell->id,
714
                $talent->spell->name,
715
                $talent->spell->icon,
716
                $talent->spell->description,
717
                $talent->spell->castTime,
718
                $cooldown
719
            );
720
721
            $spec = $this->prepareSpecValueObject($talent->spec);
722
723
            $talents[] = new TalentsValueObject(
724
                $talent->tier,
725
                $talent->column,
726
                $spell,
727
                $spec
728
            );
729
        }
730
731
        return $talents;
732
    }
733
734
    /**
735
     * @param \StdClass $spec
736
     * @return SpecValueObject
737
     */
738
    private function prepareSpecValueObject($spec)
739
    {
740
        return new SpecValueObject(
741
            $spec->name,
742
            $spec->role,
743
            $spec->backgroundImage,
744
            $spec->icon,
745
            $spec->description,
746
            $spec->order
747
        );
748
    }
749
}
750