ConfigAchievementProvider::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 5
nc 4
nop 1
1
<?php
2
/**
3
 * ConfigAchievementProvider
4
 *
5
 * @category  AxalianAchievements\AchievementProvider
6
 * @package   AxalianAchievements\AchievementProvider
7
 * @author    Michel Maas <[email protected]>
8
 */
9
10
namespace AxalianAchievements\AchievementProvider;
11
12
use AxalianAchievements\Entity\Achievement;
13
use AxalianAchievements\Entity\Category;
14
15
class ConfigAchievementProvider implements AchievementProviderInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $achievements;
21
22
    /**
23
     * @var array
24
     */
25
    protected $categories;
26
27
    public function __construct(array $config)
28
    {
29
30
        if (isset($config['categories'])) {
31
            $this->setCategories($config['categories']);
32
        }
33
34
        if (isset($config['categories'])) {
35
            $this->setAchievements($config['achievements']);
36
        }
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getAchievements()
43
    {
44
        return $this->achievements;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getCategories()
51
    {
52
        return $this->categories;
53
    }
54
55
    /**
56
     * @param array $achievements
57
     * @return ConfigAchievementProvider
58
     */
59
    public function setAchievements($achievements)
60
    {
61
        foreach ($achievements as $achievementID => $achievementConfig) {
62
            $this->achievements[] = new Achievement($achievementID, $achievementConfig);
63
        }
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param array $categories
70
     * @return ConfigAchievementProvider
71
     */
72
    public function setCategories($categories)
73
    {
74
        foreach ($categories as $categoryID => $categoryConfig) {
75
            $this->categories[] = new Category($categoryID, $categoryConfig);
76
        }
77
78
        return $this;
79
    }
80
}
81