| Conditions | 13 |
| Total Lines | 40 |
| 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 |
||
| 38 | function run(\CharlotteDunois\Livia\Commands\Context $context, \ArrayObject $args, bool $fromPattern) { |
||
| 39 | if(empty($args['prefix'])) { |
||
| 40 | $prefix = $this->client->getGuildPrefix($context->message->guild); |
||
| 41 | $msg = ($prefix !== null ? 'The command prefix is `'.$prefix.'`.' : 'There is no command prefix set.').\PHP_EOL.'To run commands, use '.\CharlotteDunois\Livia\Commands\Command::anyUsage('command', $prefix, $this->client->user).'.'; |
||
| 42 | return $context->say($msg); |
||
| 43 | } |
||
| 44 | |||
| 45 | if($context->message->guild !== null) { |
||
| 46 | if(!$context->message->member->permissions->has('ADMINISTRATOR') && !$this->client->isOwner($context->message->author)) { |
||
| 47 | return $context->reply('Only administrators may change the command prefix.'); |
||
| 48 | } |
||
| 49 | } elseif(!$this->client->isOwner($context->message->author)) { |
||
| 50 | return $context->reply('Only the bot owner may change the command prefix.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | $prefixLc = \mb_strtolower($args['prefix']); |
||
| 54 | $prefix = ($prefixLc === 'none' ? null : $args['prefix']); |
||
| 55 | $guild = $context->message->guild; |
||
| 56 | |||
| 57 | if($prefixLc === 'default') { |
||
| 58 | if($guild !== null) { |
||
| 59 | $this->client->setGuildPrefix($guild, ''); |
||
| 60 | } else { |
||
| 61 | $this->client->setCommandPrefix(null); |
||
| 62 | } |
||
| 63 | |||
| 64 | $prefix = $this->client->commandPrefix; |
||
| 65 | $current = ($this->client->commandPrefix ? '`'.$this->client->commandPrefix.'`' : 'no prefix'); |
||
| 66 | $response = 'Reset the command prefix to the default (currently '.$current.').'; |
||
| 67 | } else { |
||
| 68 | if($guild !== null) { |
||
| 69 | $this->client->setGuildPrefix($guild, $prefix); |
||
| 70 | } else { |
||
| 71 | $this->client->setCommandPrefix($prefix); |
||
| 72 | } |
||
| 73 | |||
| 74 | $response = ($prefix ? 'Set the command prefix to `'.$prefix.'`.' : 'Removed the command prefix entirely.'); |
||
| 75 | } |
||
| 76 | |||
| 77 | return $context->reply($response.' To run commands use '.\CharlotteDunois\Livia\Commands\Command::anyUsage('command', $prefix, $this->client->user)); |
||
| 78 | } |
||
| 81 |