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

GameDataStorage::getGameInfos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
}