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

GdaemonCommandsService::replaceShortCodes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
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
}