Test Setup Failed
Branch develop (2163ff)
by Nikita
06:04
created

GameModResponse::jsonSerialize()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 25
rs 9.584
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Gameap\Http\Responses\GdaemonAPI;
4
5
class GameModResponse implements \JsonSerializable
6
{
7
    /** @var \Gameap\Models\GameMod */
8
    private $gameMod;
9
10
    /** @var string */
11
    private $os;
12
13
    public function __construct(\Gameap\Models\GameMod $gameMod, string $os = 'linux')
14
    {
15
        $this->gameMod = $gameMod;
16
        $this->os = $os;
17
    }
18
19
    public function jsonSerialize()
20
    {
21
        $remoteRepository = '';
22
        $localRepository = '';
23
        $defaultStartCmd = '';
24
        if ($this->os === 'linux') {
25
            $remoteRepository = $this->gameMod->remote_repository_linux;
26
            $localRepository = $this->gameMod->local_repository_linux;
27
            $defaultStartCmd = $this->gameMod->start_cmd_linux;
28
        } elseif ($this->os === 'windows') {
29
            $remoteRepository = $this->gameMod->remote_repository_windows;
30
            $localRepository = $this->gameMod->local_repository_windows;
31
            $defaultStartCmd = $this->gameMod->start_cmd_windows;
32
        }
33
34
        return [
35
            'id' => $this->gameMod->id,
36
            'game_code' => $this->gameMod->game_code,
37
            'name' => $this->gameMod->name,
38
            'vars' => $this->gameMod->vars,
39
            'remote_repository' => $remoteRepository,
40
            'local_repository' => $localRepository,
41
            'default_start_cmd' => $defaultStartCmd,
42
            'default_start_cmd_linux' => $this->gameMod->start_cmd_linux,
43
            'default_start_cmd_windows' => $this->gameMod->start_cmd_windows,
44
        ];
45
    }
46
}
47