ProfessionService::prepareProfessionsValueObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Profession\Service;
4
5
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Profession\Model\ProfessionsValueObject;
6
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Profession\Model\ProfessionValueObject;
7
8
/**
9
 * @author  Willy Reiche
10
 * @since   2017-08-28
11
 * @version 1.0
12
 */
13
class ProfessionService
14
{
15
    /**
16
     * @param \StdClass $professions
17
     *
18
     * @return ProfessionsValueObject
19
     */
20
    public function prepareProfessionsValueObject($professions)
21
    {
22
        $primaryProfessions = $this->prepareProfessionValueObject($professions->primary);
23
        $secondaryProfessions = $this->prepareProfessionValueObject($professions->secondary);
24
25
        $professions = new ProfessionsValueObject(
26
            $primaryProfessions,
27
            $secondaryProfessions
28
        );
29
30
        return $professions;
31
    }
32
33
    /**
34
     * @param \StdClass[] $professions
35
     *
36
     * @return ProfessionValueObject[]
37
     */
38
    private function prepareProfessionValueObject($professions) {
39
        $characterProfessions = [];
40
41
        foreach ($professions as $profession) {
42
            $characterProfessions[] = new ProfessionValueObject(
43
                $profession->id,
44
                $profession->name,
45
                $profession->icon,
46
                $profession->rank,
47
                $profession->max,
48
                $profession->recipes
49
            );
50
        }
51
52
        return $characterProfessions;
53
    }
54
}
55