Completed
Push — master ( e138c6...ff3199 )
by De Cramer
01:42 queued 01:39
created

GameDataStorage::getTitleGame()   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
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace eXpansion\Framework\Core\Storage;
4
5
use eXpansion\Framework\Core\Helpers\CompatibleFetcher;
6
use eXpansion\Framework\Core\Helpers\Countries;
7
use Maniaplanet\DedicatedServer\Structures\GameInfos;
8
use Maniaplanet\DedicatedServer\Structures\ServerOptions;
9
use Maniaplanet\DedicatedServer\Structures\SystemInfos;
10
use Maniaplanet\DedicatedServer\Structures\Version;
11
use oliverde8\AssociativeArraySimplified\AssociativeArray;
12
13
/**
14
 * Class GameDataStorage
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2017 eXpansion
18
 * @package   eXpansion\Framework\Core\Storage
19
 */
20
class GameDataStorage
21
{
22
    /**
23
     * Constant used for unknown game modes.
24
     */
25
    const GAME_MODE_CODE_UNKNOWN = 'unknown';
26
27
    /**
28
     * Constants for the operating system.
29
     */
30
    const OS_LINUX = 'Linux';
31
    const OS_WINDOWS = 'Windows';
32
    const OS_MAC = 'Mac';
33
34
35
    /** @var Countries */
36
    protected $countriesHelper;
37
38
    /** @var  SystemInfos */
39
    protected $systemInfo;
40
41
    /** @var  ServerOptions */
42
    protected $serverOptions;
43
44
    /** @var array */
45
    protected $scriptOptions;
46
47
    /** @var  GameInfos */
48
    protected $gameInfos;
49
50
    /** @var Version */
51
    protected $version;
52
53
    /**
54
     * @var AssociativeArray
55
     */
56
    protected $gameModeCodes;
57
58
    /** @var string */
59
    protected $mapFolder;
60
61
    /** @var string */
62
    protected $serverCleanPhpVersion;
63
64
    /** @var string */
65
    protected $serverMajorPhpVersion;
66
    /**
67
     * @var CompatibleFetcher
68
     */
69
    private $compatibleFetcher;
70
71
    /**
72
     * GameDataStorage constructor.
73
     *
74
     * @param CompatibleFetcher $compatibleFetcher
75
     * @param Countries         $countries
76
     * @param array             $gameModeCodes
77
     */
78 150
    public function __construct(CompatibleFetcher $compatibleFetcher, Countries $countries, array $gameModeCodes)
0 ignored issues
show
Unused Code introduced by
The parameter $countries is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80 150
        $this->gameModeCodes = new AssociativeArray($gameModeCodes);
81
82 150
        $version = explode('-', phpversion());
83 150
        $this->serverCleanPhpVersion = $version[0];
84 150
        $this->serverMajorPhpVersion = implode(
85 150
            '.',
86 150
            array_slice(explode('.', $this->serverCleanPhpVersion), 0, 2)
87
        );
88
89 150
        $this->compatibleFetcher = $compatibleFetcher;
90 150
    }
91
92
93
    /**
94
     * @return GameInfos
95
     */
96
    public function getGameInfos()
97
    {
98
        return $this->gameInfos;
99
    }
100
101
    /**
102
     * @param GameInfos $gameInfos
103
     */
104
    public function setGameInfos($gameInfos)
105
    {
106
        $gameInfos->scriptName = strtolower($gameInfos->scriptName);
107
        $this->gameInfos = $gameInfos;
108
    }
109
110
    /**
111
     * @return Version
112
     */
113
    public function getVersion()
114
    {
115
        return $this->version;
116
    }
117
118
    /**
119
     * @param Version $version
120
     */
121
    public function setVersion($version)
122
    {
123
        $this->version = $version;
124
    }
125
126
127
    /**
128
     * Get code of the game mode.
129
     *
130
     * @return mixed
131
     */
132
    public function getGameModeCode()
133
    {
134
        return $this->gameModeCodes->get($this->getGameInfos()->gameMode, self::GAME_MODE_CODE_UNKNOWN);
135
    }
136
137
    /**
138
     *
139
     * Get the title name, this returns a simplified title name such as TM
140
     * @return string
141
     */
142
    public function getTitleGame()
143
    {
144
        return $this->compatibleFetcher->getTitleGame($this->getTitle());
145
    }
146
147
    /**
148
     * Get titlepack name such as TMStadium@nadeo
149
     * @return mixed
150
     */
151
    public function getTitle()
152
    {
153
        return $this->getVersion()->titleId;
154
    }
155
156
    /**
157
     * @return ServerOptions
158
     */
159
    public function getServerOptions()
160
    {
161
        return $this->serverOptions;
162
    }
163
164
    /**
165
     * @param ServerOptions $serverOptions
166
     */
167
    public function setServerOptions($serverOptions)
168
    {
169
        $this->serverOptions = $serverOptions;
170
    }
171
172
    /**
173
     * @return array
174
     */
175
    public function getScriptOptions(): array
176
    {
177
        return $this->scriptOptions;
178
    }
179
180
    /**
181
     * @param array $scriptOptions
182
     */
183
    public function setScriptOptions(array $scriptOptions)
184
    {
185
        $this->scriptOptions = $scriptOptions;
186
    }
187
188
    /**
189
     * @param Systeminfos $systemInfo
190
     */
191
    public function setSystemInfo(Systeminfos $systemInfo)
192
    {
193
        $this->systemInfo = $systemInfo;
194
    }
195
196
    /**
197
     * @return SystemInfos
198
     */
199
    public function getSystemInfo()
200
    {
201
        return $this->systemInfo;
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    public function getMapFolder(): string
208
    {
209
        return $this->mapFolder;
210
    }
211
212
    /**
213
     * @param string $mapFolder
214
     */
215
    public function setMapFolder(string $mapFolder)
216
    {
217
        $this->mapFolder = $mapFolder;
218
    }
219
220
    /**
221
     * Get the country the server is on.
222
     *
223
     * @return string
224
     */
225
    public function getServerCountry()
226
    {
227
        return 'Other';
228
    }
229
230
    /**
231
     * Get Operating system.
232
     *
233
     * @return string
234
     */
235
    public function getServerOs()
236
    {
237
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
238
            return self::OS_WINDOWS;
239
        } else {
240
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') {
241
                return self::OS_MAC;
242
            } else {
243
                return self::OS_LINUX;
244
            }
245
        }
246
    }
247
248
    /**
249
     * Get clean php version without build information.
250
     */
251
    public function getServerCleanPhpVersion()
252
    {
253
        return $this->serverCleanPhpVersion;
254
    }
255
256
    /**
257
     * Get the major php version numbers. 7.0 for exemple.
258
     */
259
    public function getServerMajorPhpVersion()
260
    {
261
        return $this->serverMajorPhpVersion;
262
    }
263
}
264