Passed
Push — master ( 52dd57...a4c9fa )
by Willy
02:14
created

CollectionService::prepareCollectionValueObject()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 9.2
cc 4
eloc 14
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Service;
4
5
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\CollectionValueObject;
6
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\MountValueObject;
7
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\PetStatValueObject;
8
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\PetValueObject;
9
10
/**
11
 * @author  Willy Reiche
12
 * @since   2017-08-28
13
 * @version 1.0
14
 */
15
class CollectionService
16
{
17
    const MOUNT = 'MOUNT';
18
    const PET = 'PET';
19
20
    /**
21
     * @param \StdClass $object
22
     * @param string $type
23
     *
24
     * @return CollectionValueObject
25
     */
26 2
    public function prepareCollectionValueObject($object, $type)
27
    {
28 2
        $collected = [];
29 2
        foreach ($object->collected as $collect) {
30
            switch ($type) {
31 2
                case self::MOUNT:
32 1
                    $collected[] = $this->prepareMountValueObject($collect);
33 1
                    break;
34 1
                case self::PET:
35 1
                    $collected[] = $this->preparePetValueObject($collect);
36 1
                    break;
37
            }
38 2
        }
39
40 2
        return new CollectionValueObject(
41 2
            $object->numCollected,
42 2
            $object->numNotCollected,
43
            $collected
44 2
        );
45
    }
46
47
    /**
48
     * @param \StdClass $mount
49
     * @return MountValueObject
50
     */
51 1
    private function prepareMountValueObject(\StdClass $mount)
52
    {
53 1
        return new MountValueObject(
54 1
            $mount->name,
55 1
            $mount->spellId,
56 1
            $mount->creatureId,
57 1
            $mount->itemId,
58 1
            $mount->qualityId,
59 1
            $mount->icon,
60 1
            $mount->isGround,
61 1
            $mount->isFlying,
62 1
            $mount->isAquatic,
63 1
            $mount->isJumping
64 1
        );
65
    }
66
67
    /**
68
     * @param \StdClass $pet
69
     * @return PetValueObject
70
     */
71 1
    private function preparePetValueObject($pet)
72
    {
73 1
        $petStatValueObject = $this->preparePetStatsValueObject($pet->stats);
74
75 1
        return new PetValueObject(
76 1
            $pet->name,
77 1
            $pet->spellId,
78 1
            $pet->creatureId,
79 1
            $pet->itemId,
80 1
            $pet->qualityId,
81 1
            $pet->icon,
82 1
            $petStatValueObject,
83 1
            $pet->battlePetGuid,
84 1
            $pet->isFavorite,
85 1
            $pet->isFirstAbilitySlotSelected,
86 1
            $pet->isSecondAbilitySlotSelected,
87 1
            $pet->isThirdAbilitySlotSelected,
88 1
            $pet->creatureName,
89 1
            $pet->canBattle
90 1
        );
91
    }
92
93
    /**
94
     * @param \StdClass $stats
95
     * @return PetStatValueObject
96
     */
97 1
    private function preparePetStatsValueObject($stats)
98
    {
99 1
        return new PetStatValueObject(
100 1
            $stats->speciesId,
101 1
            $stats->breedId,
102 1
            $stats->petQualityId,
103 1
            $stats->level,
104 1
            $stats->health,
105 1
            $stats->power,
106 1
            $stats->speed
107 1
        );
108
    }
109
}
110