Test Failed
Push — develop ( af7e45...e70623 )
by Nikita
08:39
created

DedicatedServer::gdaemonSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 1
dl 0
loc 26
rs 9.6
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_get_console
44
 * @property string $script_send_command
45
 * @property string $script_delete
46
 * @property string $created_at
47
 * @property string $updated_at
48
 *
49
 * @property Server[] $servers
50
 * @property ClientCertificate $clientCertificate
51
 */
52
class DedicatedServer extends Model implements ValidableContract
53
{
54
    use Validable;
55
    
56
    /**
57
     * The attributes that are mass assignable.
58
     *
59
     * @var array
60
     */
61
    protected $fillable = [
62
        'enabled', 
63
        'name', 
64
        'os',
65
        'location', 
66
        'provider', 
67
        'ip',
68
        'ram',
69
        'cpu', 
70
        'work_path',
71
        'steamcmd_path', 
72
        'gdaemon_host',
73
        'gdaemon_port',
74
        'gdaemon_login',
75
        'gdaemon_password',
76
        'gdaemon_server_cert',
77
        'client_certificate_id',
78
        'prefer_install_method',
79
        'script_install',
80
        'script_reinstall',
81
        'script_update',
82
        'script_start',
83
        'script_pause',
84
        'script_unpause',
85
        'script_stop', 
86
        'script_kill', 
87
        'script_restart',
88
        'script_status', 
89
        'script_get_console',
90
        'script_send_command',
91
        'script_delete',
92
    ];
93
94
    protected $casts = [
95
        'ip' => 'array',
96
    ];
97
98
    /**
99
     * Validation rules
100
     * @var array
101
     */
102
    protected static $rules = [
103
        'name' => 'required|max:128',
104
        'location' => 'required|max:128',
105
        // 'ip' => 'required|array',
106
        'work_path' => 'required|max:128',
107
        'gdaemon_host' => 'required|max:128',
108
        'gdaemon_port' => 'required|numeric|digits_between:1,65535',
109
        'gdaemon_login' => 'max:128',
110
        'gdaemon_password' => 'max:128',
111
        'gdaemon_server_cert' => 'max:128',
112
        'client_certificate_id' => 'numeric|exists:client_certificates,id',
113
    ];
114
115
    /**
116
     * One to many relation
117
     *
118
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
119
     */
120
    public function servers()
121
    {
122
        return $this->hasMany(Server::class, 'ds_id');
123
    }
124
125
    /**
126
     * One to one relation
127
     */
128
    public function clientCertificate()
129
    {
130
        return $this->belongsTo(ClientCertificate::class);
131
    }
132
133
    /**
134
     * @param $storageDisk
135
     * @return array
136
     */
137
    public function gdaemonSettings($storageDisk)
138
    {
139
        return [
140
            'host' => $this->gdaemon_host,
141
            'port' => $this->gdaemon_port,
142
            'username' => $this->gdaemon_login,
143
            'password' => $this->gdaemon_password,
144
145
            'serverCertificate' => Storage::disk($this->storageDisk)
0 ignored issues
show
Bug introduced by
The property storageDisk does not seem to exist on Gameap\Models\DedicatedServer. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
146
                ->getDriver()
147
                ->getAdapter()
148
                ->applyPathPrefix($this->gdaemon_server_cert),
149
150
            'localCertificate' => Storage::disk($storageDisk)
151
                ->getDriver()
152
                ->getAdapter()
153
                ->applyPathPrefix($this->clientCertificate->certificate),
154
155
            'privateKey' => Storage::disk($this->storageDisk)
156
                ->getDriver()
157
                ->getAdapter()
158
                ->applyPathPrefix($this->clientCertificate->private_key),
159
160
            'privateKeyPass' => $this->clientCertificate->private_key_pass,
161
            'workDir' => $this->work_path,
162
            'timeout' => 10,
163
        ];
164
    }
165
}
166