Completed
Push — dev ( 8eacd8...04be10 )
by De Cramer
02:44
created

GameDataStorage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 2
cbo 3
dl 0
loc 92
ccs 4
cts 18
cp 0.2222
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getGameInfos() 0 4 1
A setGameInfos() 0 4 1
A getVersion() 0 4 1
A setVersion() 0 4 1
A getGameModeCode() 0 4 1
A getTitle() 0 4 1
1
<?php
2
3
namespace eXpansion\Framework\Core\Storage;
4
use Maniaplanet\DedicatedServer\Structures\GameInfos;
5
use Maniaplanet\DedicatedServer\Structures\Version;
6
use oliverde8\AssociativeArraySimplified\AssociativeArray;
7
8
/**
9
 * Class GameDataStorage
10
 *
11
 * @author    de Cramer Oliver<[email protected]>
12
 * @copyright 2017 Smile
13
 * @package eXpansion\Framework\Core\Storage
14
 */
15
class GameDataStorage
16
{
17
    /**
18
     * Constant used for unknown game modes.
19
     */
20
    const GAME_MODE_CODE_UNKNOWN = 'unknown';
21
22
    /**
23
     * Constant used for unknown titles.
24
     */
25
    const TITLE_UNKNOWN = 'unknown';
26
27
    /** @var  GameInfos */
28
    protected $gameInfos;
29
30
    /** @var Version */
31
    protected $version;
32
33
    /**
34
     * @var AssociativeArray
35
     */
36
    protected $gameModeCodes;
37
38
    /**
39
     * @var AssociativeArray
40
     */
41
    protected $titles;
42
43
    /**
44
     * GameDataStorage constructor.
45
     *
46
     * @param array $gameModeCodes
47
     */
48 45
    public function __construct(array $gameModeCodes, array $titles)
49
    {
50 45
        $this->gameModeCodes = new AssociativeArray($gameModeCodes);
51 45
        $this->titles = new AssociativeArray($titles);
52 45
    }
53
54
55
    /**
56
     * @return GameInfos
57
     */
58
    public function getGameInfos()
59
    {
60
        return $this->gameInfos;
61
    }
62
63
    /**
64
     * @param GameInfos $gameInfos
65
     */
66
    public function setGameInfos($gameInfos)
67
    {
68
        $this->gameInfos = $gameInfos;
69
    }
70
71
    /**
72
     * @return Version
73
     */
74
    public function getVersion()
75
    {
76
        return $this->version;
77
    }
78
79
    /**
80
     * @param Version $version
81
     */
82
    public function setVersion($version)
83
    {
84
        $this->version = $version;
85
    }
86
87
    /**
88
     * Get code of the game mode.
89
     *
90
     * @return mixed
91
     */
92
    public function getGameModeCode()
93
    {
94
        return $this->gameModeCodes->get($this->getGameInfos()->gameMode, self::GAME_MODE_CODE_UNKNOWN);
95
    }
96
97
    /**
98
     * Get the title name, this returns a simplified title name such as TM
99
     *
100
     * @return mixed
101
     */
102
    public function getTitle()
103
    {
104
        return $this->titles->get($this->getVersion()->titleId, self::TITLE_UNKNOWN);
105
    }
106
}