| Conditions | 15 |
| Paths | 2187 |
| Total Lines | 54 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 45 | public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
||
| 46 | /** @var ISchemaWrapper $schema */ |
||
| 47 | $schema = $schemaClosure(); |
||
| 48 | |||
| 49 | if ($schema->hasTable('polls_options')) { |
||
| 50 | $table = $schema->getTable('polls_options'); |
||
| 51 | if (!$table->hasIndex('UNIQ_options')) { |
||
| 52 | $table->addUniqueIndex(['poll_id', 'poll_option_text', 'timestamp'], 'UNIQ_options'); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($schema->hasTable('polls_log')) { |
||
| 57 | $table = $schema->getTable('polls_log'); |
||
| 58 | if (!$table->hasIndex('UNIQ_unprocessed')) { |
||
| 59 | $table->addUniqueIndex(['processed', 'poll_id', 'user_id', 'message_id'], 'UNIQ_unprocessed'); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($schema->hasTable('polls_notif')) { |
||
| 64 | $table = $schema->getTable('polls_notif'); |
||
| 65 | if (!$table->hasIndex('UNIQ_subscription')) { |
||
| 66 | $table->addUniqueIndex(['poll_id', 'user_id'], 'UNIQ_subscription'); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($schema->hasTable('polls_share')) { |
||
| 71 | $table = $schema->getTable('polls_share'); |
||
| 72 | if (!$table->hasIndex('UNIQ_shares')) { |
||
| 73 | $table->addUniqueIndex(['poll_id', 'user_id'], 'UNIQ_shares'); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($schema->hasTable('polls_votes')) { |
||
| 78 | $table = $schema->getTable('polls_votes'); |
||
| 79 | if (!$table->hasIndex('UNIQ_votes')) { |
||
| 80 | $table->addUniqueIndex(['poll_id', 'user_id', 'vote_option_text'], 'UNIQ_votes'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($schema->hasTable('polls_preferences')) { |
||
| 85 | $table = $schema->getTable('polls_preferences'); |
||
| 86 | if (!$table->hasIndex('UNIQ_preferences')) { |
||
| 87 | $table->addUniqueIndex(['user_id'], 'UNIQ_preferences'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($schema->hasTable('polls_watch')) { |
||
| 92 | $table = $schema->getTable('polls_watch'); |
||
| 93 | if (!$table->hasIndex('UNIQ_watch')) { |
||
| 94 | $table->addUniqueIndex(['poll_id', 'table'], 'UNIQ_watch'); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | return $schema; |
||
| 99 | } |
||
| 101 |