Conditions | 24 |
Paths | 249 |
Total Lines | 56 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
62 | public function preUpdate(PreUpdateEventArgs $args) |
||
63 | { |
||
64 | $entity = $args->getEntity(); |
||
65 | |||
66 | if ($entity instanceof SteamServer) { |
||
67 | if ($args->hasChangedField('port') |
||
68 | || ($args->hasChangedField('maxplayers') && $entity->getGame()->getLaunchName() != "csgo") |
||
69 | || $args->hasChangedField('core') || $args->hasChangedField('mode')) { |
||
70 | try { |
||
71 | $entity->uploadHldsScript($this->getTwig()); |
||
72 | } |
||
73 | catch (\Exception $e) {} |
||
74 | } |
||
75 | if ($args->hasChangedField('maxplayers') && $entity->getGame()->getLaunchName() == "csgo") { |
||
76 | try { |
||
77 | $entity->modifyGameModesCfg(); |
||
78 | } |
||
79 | catch (\Exception $e) {} |
||
80 | } |
||
81 | if ($args->hasChangedField('dir')) { |
||
82 | try { |
||
83 | $entity->uploadShellScripts($this->getTwig()); |
||
84 | } |
||
85 | catch (\Exception $e) {} |
||
86 | } |
||
87 | if ($args->hasChangedField('rebootAt')) { |
||
88 | //suppression del'ancienne tâche cron |
||
89 | $entity->removeAutoReboot($args->getOldValue('rebootAt')); |
||
90 | |||
91 | if ($args->getNewValue('rebootAt') != null) { |
||
92 | $entity->addAutoReboot(); |
||
93 | } |
||
94 | } |
||
95 | if ($args->hasChangedField('name') || $args->hasChangedField('rconPassword')) { |
||
96 | try { |
||
97 | $entity->modifyServerCfgFile(); |
||
98 | } |
||
99 | catch (\Exception $e) {} |
||
100 | } |
||
101 | } |
||
102 | elseif ($entity instanceof Machine) { |
||
103 | // Upload des scripts si l'IP publique ou le home de la machine a été modifié |
||
104 | if ($args->hasChangedField('publicIp') || $args->hasChangedField('home')) { |
||
105 | $servers = $entity->getGameServers(); |
||
106 | |||
107 | foreach ($servers AS $server) { |
||
108 | if (!$server instanceof SteamServer) continue; |
||
109 | |||
110 | try { |
||
111 | $server->uploadShellScripts($this->getTwig()); |
||
112 | } |
||
113 | catch (\Exception $e) {} |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 |