Completed
Push — master ( 2a3483...c07a8d )
by De Cramer
02:05 queued 02:03
created

GameDataStorage::getMapFolder()   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
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 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\Countries;
6
use Maniaplanet\DedicatedServer\Structures\GameInfos;
7
use Maniaplanet\DedicatedServer\Structures\ServerOptions;
8
use Maniaplanet\DedicatedServer\Structures\SystemInfos;
9
use Maniaplanet\DedicatedServer\Structures\Version;
10
use oliverde8\AssociativeArraySimplified\AssociativeArray;
11
12
/**
13
 * Class GameDataStorage
14
 *
15
 * @author    de Cramer Oliver<[email protected]>
16
 * @copyright 2017 eXpansion
17
 * @package   eXpansion\Framework\Core\Storage
18
 */
19
class GameDataStorage
20
{
21
    /**
22
     * Constant used for unknown game modes.
23
     */
24
    const GAME_MODE_CODE_UNKNOWN = 'unknown';
25
26
    /**
27
     * Constant used for unknown titles.
28
     */
29
    const TITLE_UNKNOWN = 'unknown';
30
31
    /** @var Countries */
32
    protected $countriesHelper;
33
34
    /** @var  SystemInfos */
35
    protected $systemInfo;
36
37
    /** @var  ServerOptions */
38
    protected $serverOptions;
39
40
    /** @var array */
41
    protected $scriptOptions;
42
43
    /** @var  GameInfos */
44
    protected $gameInfos;
45
46
    /** @var Version */
47
    protected $version;
48
49
    /**
50
     * @var AssociativeArray
51
     */
52
    protected $gameModeCodes;
53
54
    /** @var string */
55
    protected $mapFolder;
56
57
    /**
58
     * @var AssociativeArray
59
     */
60
    protected $titles;
61
62
    /** @var string */
63
    protected $serverCleanPhpVersion;
64
65
    /** @var string */
66
    protected $serverMajorPhpVersion;
67
68
    /**
69
     * GameDataStorage constructor.
70
     *
71
     * @param Countries $countries
72
     * @param array $gameModeCodes
73
     * @param array $titles
74
     */
75 141
    public function __construct(Countries $countries, array $gameModeCodes, array $titles)
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...
76
    {
77 141
        $this->gameModeCodes = new AssociativeArray($gameModeCodes);
78 141
        $this->titles = new AssociativeArray($titles);
79
80 141
        $version = explode('-', phpversion());
81 141
        $this->serverCleanPhpVersion = $version[0];
82 141
        $this->serverMajorPhpVersion = implode(
83 141
            '.',
84 141
            array_slice(explode('.', $this->serverCleanPhpVersion),0,2)
85
        );
86 141
    }
87
88
89
    /**
90
     * @return GameInfos
91
     */
92
    public function getGameInfos()
93
    {
94
        return $this->gameInfos;
95
    }
96
97
    /**
98
     * @param GameInfos $gameInfos
99
     */
100
    public function setGameInfos($gameInfos)
101
    {
102
        $this->gameInfos = $gameInfos;
103
    }
104
105
    /**
106
     * @return Version
107
     */
108
    public function getVersion()
109
    {
110
        return $this->version;
111
    }
112
113
    /**
114
     * @param Version $version
115
     */
116
    public function setVersion($version)
117
    {
118
        $this->version = $version;
119
    }
120
121
    /**
122
     * Get code of the game mode.
123
     *
124
     * @return mixed
125
     */
126
    public function getGameModeCode()
127
    {
128
        return $this->gameModeCodes->get($this->getGameInfos()->gameMode, self::GAME_MODE_CODE_UNKNOWN);
129
    }
130
131
    /**
132
     * Get the title name, this returns a simplified title name such as TM
133
     *
134
     * @return mixed
135
     */
136
    public function getTitle()
137
    {
138
139
        $title = $this->titles->get($this->getVersion()->titleId, self::TITLE_UNKNOWN);
140
        if ($title == self::TITLE_UNKNOWN) {
141
            if (substr($this->getVersion()->titleId, 0, 2) == "TM") {
142
                return "TM";
143
            }
144
            if (substr($this->getVersion()->titleId, 0, 2) == "SM") {
145
                return "SM";
146
            }
147
        }
148
149
        return $title;
150
    }
151
152
    /**
153
     * @return ServerOptions
154
     */
155
    public function getServerOptions()
156
    {
157
        return $this->serverOptions;
158
    }
159
160
    /**
161
     * @param ServerOptions $serverOptions
162
     */
163
    public function setServerOptions($serverOptions)
164
    {
165
        $this->serverOptions = $serverOptions;
166
    }
167
168
    /**
169
     * @return array
170
     */
171
    public function getScriptOptions(): array
172
    {
173
        return $this->scriptOptions;
174
    }
175
176
    /**
177
     * @param array $scriptOptions
178
     */
179
    public function setScriptOptions(array $scriptOptions)
180
    {
181
        $this->scriptOptions = $scriptOptions;
182
    }
183
184
    /**
185
     * @param Systeminfos $systemInfo
186
     */
187
    public function setSystemInfo(Systeminfos $systemInfo)
188
    {
189
        $this->systemInfo = $systemInfo;
190
    }
191
192
    /**
193
     * @return SystemInfos
194
     */
195
    public function getSystemInfo()
196
    {
197
        return $this->systemInfo;
198
    }
199
200
    /**
201
     * @return string
202
     */
203
    public function getMapFolder(): string
204
    {
205
        return $this->mapFolder;
206
    }
207
208
    /**
209
     * @param string $mapFolder
210
     */
211
    public function setMapFolder(string $mapFolder)
212
    {
213
        $this->mapFolder = $mapFolder;
214
    }
215
216
    /**
217
     * Get the country the server is on.
218
     *
219
     * @return string
220
     */
221
    public function getServerCountry()
222
    {
223
        return 'Other';
224
    }
225
226
    /**
227
     * Get Operating system.
228
     *
229
     * @return string
230
     */
231
    public function getServerOs()
232
    {
233
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
234
            return "Windows";
235
        } else {
236
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') {
237
                return "Mac";
238
            } else {
239
                return "Linux";
240
            }
241
        }
242
    }
243
244
    /**
245
     * Get clean php version without build information.
246
     */
247
    public function getServerCleanPhpVersion()
248
    {
249
        return $this->serverCleanPhpVersion;
250
    }
251
252
    /**
253
     * Get the major php version numbers. 7.0 for exemple.
254
     */
255
    public function getServerMajorPhpVersion()
256
    {
257
        return $this->serverMajorPhpVersion;
258
    }
259
}
260