Conditions | 7 |
Paths | 48 |
Total Lines | 59 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public function __invoke(CreateGameServerCommand $command): array |
||
38 | { |
||
39 | $server = new Server(); |
||
40 | |||
41 | $server->uuid = Str::orderedUuid()->toString(); |
||
42 | $server->uuid_short = Str::substr($server->uuid, 0, 8); |
||
43 | $server->ds_id = $command->dsId; |
||
44 | $server->name = $command->name; |
||
45 | $server->game_id = $command->gameId; |
||
46 | $server->game_mod_id = $command->gameModId; |
||
47 | $server->server_ip = $command->serverIp; |
||
48 | $server->server_port = $command->serverPort; |
||
49 | $server->query_port = $command->queryPort; |
||
50 | $server->rcon_port = $command->rconPort; |
||
51 | $server->su_user = $command->suUser; |
||
52 | |||
53 | $server->enabled = true; |
||
54 | $server->blocked = false; |
||
55 | |||
56 | if (empty($command->rcon)) { |
||
57 | $server->rcon = Str::random(self::DEFAULT_RCON_PASSWORD_LENGTH); |
||
58 | } else { |
||
59 | $server->rcon = $command->rcon; |
||
60 | } |
||
61 | |||
62 | $node = $this->nodeRepository->findById($command->dsId); |
||
63 | |||
64 | if (empty($command->startCommand)) { |
||
65 | $gameMod = $this->gameModRepository->getById($command->gameModId); |
||
66 | |||
67 | $server->start_command = |
||
68 | $node->isLinux() |
||
69 | ? $gameMod->start_cmd_linux |
||
70 | : $gameMod->start_cmd_windows; |
||
71 | } else { |
||
72 | $server->start_command = $command->startCommand; |
||
73 | } |
||
74 | |||
75 | if (empty($command->dir)) { |
||
76 | $server->dir = 'servers/' . $server->uuid; |
||
77 | } else { |
||
78 | $server->dir = $command->dir; |
||
79 | } |
||
80 | |||
81 | if ($command->install) { |
||
82 | $server->installed = false; |
||
83 | } |
||
84 | |||
85 | $this->serverRepository->save($server); |
||
86 | |||
87 | $taskID = 0; |
||
88 | |||
89 | if ($command->install) { |
||
90 | $taskID = $this->gdaemonTaskRepository->addServerInstall($server); |
||
91 | } |
||
92 | |||
93 | return [ |
||
94 | 'taskId' => $taskID, |
||
95 | 'serverId' => $server->id, |
||
96 | ]; |
||
99 |