Completed
Push — master ( 685af6...57cff2 )
by De Cramer
10s
created

RestartExpansion::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 2
crap 6
1
<?php
2
3
namespace eXpansion\Framework\Core\ChatCommand;
4
5
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
6
use eXpansion\Framework\AdminGroups\Model\AbstractAdminChatCommand;
7
use eXpansion\Framework\Core\Helpers\ChatNotification;
8
use eXpansion\Framework\Core\Services\Application;
9
use eXpansion\Framework\Core\Storage\GameDataStorage;
10
use eXpansion\Framework\Core\Storage\PlayerStorage;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Process\Process;
13
14
15
/**
16
 * Class RestartExpansion
17
 *
18
 * @package eXpansion\Framework\Core\ChatCommand;
19
 * @author  oliver de Cramer <[email protected]>
20
 */
21
class RestartExpansion extends AbstractAdminChatCommand
22
{
23
    /** @var ChatNotification */
24
    protected $chatNotification;
25
26
    /** @var PlayerStorage */
27
    protected $playerStorage;
28
29
    /** @var GameDataStorage */
30
    protected $gameData;
31
32
    /** @var Application */
33
    protected $application;
34
35 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
        ChatNotification $chatNotification,
37
        PlayerStorage $playerStorage,
38
        GameDataStorage $gameData,
39
        Application $application,
40
        $command,
41
        string $permission,
42
        $aliases = [],
43
        AdminGroups $adminGroups
44
    ) {
45
        parent::__construct($command, $permission, $aliases, $adminGroups);
46
47
        $this->chatNotification = $chatNotification;
48
        $this->playerStorage = $playerStorage;
49
        $this->gameData = $gameData;
50
        $this->application = $application;
51
    }
52
53
54
    /**
55
     * Method called to execute the chat command.
56
     *
57
     * @param string         $login
58
     * @param InputInterface $input
59
     *
60
     * @return mixed
61
     */
62
    public function execute($login, InputInterface $input)
63
    {
64
        $player = $this->playerStorage->getPlayerInfo($login);
0 ignored issues
show
Unused Code introduced by
$player is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
66
        $scriptToExecute = 'run.sh';
67
        if ($this->gameData->getServerOs() == GameDataStorage::OS_WINDOWS) {
68
            $scriptToExecute = 'run.bat';
69
        }
70
71
        $player = $this->playerStorage->getPlayerInfo($login);
72
        $this->chatNotification->sendMessage(
73
            'expansion_core.chat_commands.restart.message',
74
            null,
75
            ['%nickname%' => $player->getNickName()]
76
        );
77
        $this->application->stopApplication();
78
79
        $process = new Process("bin/" . $scriptToExecute . " &");
80
        $process->start();
81
    }
82
}