Passed
Push — master ( c443ba...b9fa94 )
by Willy
02:30
created

StatisticService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 70
ccs 0
cts 45
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatistics() 0 21 3
A getStatisticsSubCategories() 0 8 2
A getCategoryStatistics() 0 21 3
1
<?php
2
3
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Service;
4
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Statistic\StatisticsValueObject;
5
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Model\Statistic\StatisticValueObject;
6
7
/**
8
 * @author  Willy Reiche
9
 * @since   2017-08-26
10
 * @version 1.0
11
 */
12
class StatisticService
13
{
14
    /**
15
     * @param $statistics
16
     *
17
     * @return StatisticsValueObject
18
     */
19
    public function getStatistics($statistics)
20
    {
21
        $categoryStatistics = [];
22
        if (isset($statistics->statistics)) {
23
            $categoryStatistics = $this->getCategoryStatistics($statistics->statistics);
24
        }
25
26
        $statisticsSubCategories = [];
27
        if (isset($statistics->subCategories)) {
28
            $statisticsSubCategories = $this->getStatisticsSubCategories($statistics->subCategories);
29
        }
30
31
        $statisticsValueObject =  new StatisticsValueObject(
32
            $statistics->id,
33
            $statistics->name,
34
            $statisticsSubCategories,
35
            $categoryStatistics
36
        );
37
38
        return $statisticsValueObject;
39
    }
40
41
    /**
42
     * @param $subCategories
43
     *
44
     * @return StatisticsValueObject[]
45
     */
46
    private function getStatisticsSubCategories($subCategories)
47
    {
48
        $categories = [];
49
        foreach ($subCategories as $subCategory) {
50
            $categories[] = $this->getStatistics($subCategory);
51
        }
52
        return $categories;
53
    }
54
55
    /**
56
     * @param $statistics
57
     *
58
     * @return StatisticValueObject[]
59
     */
60
    private function getCategoryStatistics($statistics)
61
    {
62
        $categoryStatistics = [];
63
        foreach ($statistics as $statistic) {
64
            $highest = "";
65
            if (isset($statistic->highest)) {
66
                $highest = $statistic->highest;
67
            }
68
69
            $categoryStatistics[] = new StatisticValueObject(
70
                $statistic->id,
71
                $statistic->name,
72
                $statistic->quantity,
73
                $statistic->lastUpdated,
74
                $statistic->money,
75
                $highest
76
            );
77
        }
78
79
        return $categoryStatistics;
80
    }
81
}
82