| Conditions | 23 |
| Paths | 22 |
| Total Lines | 45 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 MinecraftServer) { |
||
| 67 | if ($args->hasChangedField('port') || $args->hasChangedField('maxplayers') |
||
| 68 | || $args->hasChangedField('name') || $args->hasChangedField('queryPort') |
||
| 69 | || $args->hasChangedField('rconPort') || $args->hasChangedField('rconPassword')) { |
||
| 70 | try { |
||
| 71 | $entity->modifyServerPropertiesFile(); |
||
| 72 | } |
||
| 73 | catch (\Exception $e) {} |
||
| 74 | } |
||
| 75 | if ($args->hasChangedField('minHeap') || $args->hasChangedField('maxHeap') |
||
| 76 | || $args->hasChangedField('dir') || $args->hasChangedField('core')) { |
||
| 77 | try { |
||
| 78 | $entity->uploadShellScripts($this->getTwig()); |
||
| 79 | } |
||
| 80 | catch (\Exception $e) {} |
||
| 81 | } |
||
| 82 | } |
||
| 83 | elseif ($entity instanceof Machine) { |
||
| 84 | // Upload des scripts si l'IP public ou le home de la machine a été modifié |
||
| 85 | if ($args->hasChangedField('publicIp') || $args->hasChangedField('home')) { |
||
| 86 | $servers = $entity->getGameServers(); |
||
| 87 | |||
| 88 | foreach ($servers AS $server) { |
||
| 89 | if (!$server instanceof MinecraftServer) continue; |
||
| 90 | |||
| 91 | if ($args->hasChangedField('publicIp')) { |
||
| 92 | try { |
||
| 93 | $server->modifyServerPropertiesFile(); |
||
| 94 | } |
||
| 95 | catch (\Exception $e) {} |
||
| 96 | } |
||
| 97 | if ($args->hasChangedField('home')) { |
||
| 98 | try { |
||
| 99 | $server->uploadShellScripts($this->getTwig()); |
||
| 100 | } |
||
| 101 | catch (\Exception $e) {} |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 |