Passed
Push — develop ( 739a43...1bb101 )
by Nikita
26:31 queued 11:36
created

GdaemonCommandsService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A replaceShortCodes() 0 7 2
A configureGdaemon() 0 6 1
1
<?php
2
3
namespace Gameap\Services;
4
5
use Gameap\Models\DedicatedServer;
6
use Knik\Gameap\GdaemonCommands;
7
8
abstract class GdaemonCommandsService
9
{
10
    /**
11
     * @var GdaemonCommands
12
     */
13
    protected $gdaemonCommands;
14
15
    /**
16
     * GdaemonCommandsService constructor.
17
     *
18
     * @param GdaemonCommands $gdaemonCommands
19
     */
20
    public function __construct(GdaemonCommands $gdaemonCommands)
21
    {
22
        $this->gdaemonCommands = $gdaemonCommands;
23
    }
24
25
    /**
26
     * Setting up gdaemon commands configuration
27
     *
28
     * @param int
29
     */
30
    protected function configureGdaemon($dsId)
31
    {
32
        $dedicatedServer = DedicatedServer::findOrFail($dsId);
33
34
        $this->gdaemonCommands->setConfig(
35
            $dedicatedServer->gdaemonSettings()
36
        );
37
    }
38
39
    /**
40
     * @param string $command
41
     * @param array $codes
42
     * @return string
43
     */
44
    protected function replaceShortCodes(string $command, array $codes)
45
    {
46
        foreach ($codes as $code => $value) {
47
            $command = str_replace('{' . $code . '}', $value, $command);
48
        }
49
50
        return $command;
51
    }
52
}