Passed
Push — develop ( f0ab84...ed5e20 )
by Nikita
06:00
created

DedicatedServer::isLinux()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 10
nc 7
nop 0
dl 0
loc 14
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Gameap\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sofa\Eloquence\Validable;
7
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
8
use Storage;
9
10
/**
11
 * Class DedicatedServer
12
 *
13
 * @property int $id
14
 * @property boolean $enabled
15
 * @property string $name
16
 * @property string $os
17
 * @property string $location
18
 * @property string $provider
19
 * @property string $ip
20
 * @property string $ram
21
 * @property string $cpu
22
 * @property string $work_path
23
 * @property string $steamcmd_path
24
 * @property string $gdaemon_host
25
 * @property integer $gdaemon_port
26
 * @property string $gdaemon_api_key
27
 * @property string $gdaemon_api_token
28
 * @property string $gdaemon_login
29
 * @property string $gdaemon_password
30
 * @property string $gdaemon_server_cert
31
 * @property integer $client_certificate_id
32
 * @property string $prefer_install_method
33
 * @property string $script_install
34
 * @property string $script_reinstall
35
 * @property string $script_update
36
 * @property string $script_start
37
 * @property string $script_pause
38
 * @property string $script_unpause
39
 * @property string $script_stop
40
 * @property string $script_kill
41
 * @property string $script_restart
42
 * @property string $script_status
43
 * @property string $script_stats
44
 * @property string $script_get_console
45
 * @property string $script_send_command
46
 * @property string $script_delete
47
 * @property string $created_at
48
 * @property string $updated_at
49
 *
50
 * @property Server[] $servers
51
 * @property ClientCertificate $clientCertificate
52
 */
53
class DedicatedServer extends Model implements ValidableContract
54
{
55
    use Validable;
56
    
57
    /**
58
     * The attributes that are mass assignable.
59
     *
60
     * @var array
61
     */
62
    protected $fillable = [
63
        'enabled', 
64
        'name', 
65
        'os',
66
        'location', 
67
        'provider', 
68
        'ip',
69
        'ram',
70
        'cpu', 
71
        'work_path',
72
        'steamcmd_path', 
73
        'gdaemon_host',
74
        'gdaemon_port',
75
        'gdaemon_login',
76
        'gdaemon_password',
77
        'gdaemon_server_cert',
78
        'gdaemon_api_key',
79
        'client_certificate_id',
80
        'prefer_install_method',
81
        'script_install',
82
        'script_reinstall',
83
        'script_update',
84
        'script_start',
85
        'script_pause',
86
        'script_unpause',
87
        'script_stop', 
88
        'script_kill', 
89
        'script_restart',
90
        'script_status',
91
        'script_stats',
92
        'script_get_console',
93
        'script_send_command',
94
        'script_delete',
95
    ];
96
97
    protected $casts = [
98
        'ip' => 'array',
99
    ];
100
101
    /**
102
     * Validation rules
103
     * @var array
104
     */
105
    protected static $rules = [
106
        'name' => 'required|max:128',
107
        'location' => 'required|max:128',
108
        'ip' => 'required',
109
        'work_path' => 'required|max:128',
110
        'gdaemon_host' => 'required|max:128',
111
        'gdaemon_port' => 'required|numeric|digits_between:1,65535',
112
        'gdaemon_login' => 'max:128',
113
        'gdaemon_password' => 'max:128',
114
        'gdaemon_api_key' => '',
115
        'gdaemon_server_cert' => 'sometimes',
116
        'client_certificate_id' => 'numeric|exists:client_certificates,id',
117
    ];
118
119
    /**
120
     * One to many relation
121
     *
122
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
123
     */
124
    public function servers()
125
    {
126
        return $this->hasMany(Server::class, 'ds_id');
127
    }
128
129
    /**
130
     * One to one relation
131
     */
132
    public function clientCertificate()
133
    {
134
        return $this->belongsTo(ClientCertificate::class);
135
    }
136
137
    /**
138
     * @param $storageDisk
139
     * @return array
140
     */
141
    public function gdaemonSettings($storageDisk)
142
    {
143
        return [
144
            'host' => $this->gdaemon_host,
145
            'port' => $this->gdaemon_port,
146
            'username' => $this->gdaemon_login,
147
            'password' => $this->gdaemon_password,
148
149
            'serverCertificate' => Storage::disk($storageDisk)
150
                ->getDriver()
151
                ->getAdapter()
152
                ->applyPathPrefix($this->gdaemon_server_cert),
153
154
            'localCertificate' => Storage::disk($storageDisk)
155
                ->getDriver()
156
                ->getAdapter()
157
                ->applyPathPrefix($this->clientCertificate->certificate),
158
159
            'privateKey' => Storage::disk($storageDisk)
160
                ->getDriver()
161
                ->getAdapter()
162
                ->applyPathPrefix($this->clientCertificate->private_key),
163
164
            'privateKeyPass' => $this->clientCertificate->private_key_pass,
165
            'workDir' => $this->work_path,
166
            'timeout' => 10,
167
        ];
168
    }
169
170
    /**
171
     * @return bool
172
     */
173
    public function isLinux()
174
    {
175
        switch (strtolower($this->os)) {
176
            case 'linux':
177
            case 'debian':
178
            case 'ubuntu':
179
            case 'centos':
180
            case 'gentoo':
181
            case 'opensuse':
182
                return true;
183
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
184
        }
185
186
        return false;
187
    }
188
}
189