| Conditions | 7 |
| Paths | 16 |
| Total Lines | 85 |
| Code Lines | 56 |
| 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 |
||
| 34 | public function up(Schema $schema): void |
||
| 35 | { |
||
| 36 | $result = $this->connection->executeQuery('SELECT * FROM message WHERE user_receiver_id IS NOT NULL'); |
||
| 37 | $messages = $result->fetchAllAssociative(); |
||
| 38 | |||
| 39 | if ($messages) { |
||
| 40 | foreach ($messages as $message) { |
||
| 41 | $messageId = (int) $message['id']; |
||
| 42 | $receiverId = (int) $message['user_receiver_id']; |
||
| 43 | |||
| 44 | $result = $this->connection->executeQuery(" SELECT * FROM message_rel_user WHERE message_id = $messageId AND user_id = $receiverId"); |
||
| 45 | $exists = $result->fetchAllAssociative(); |
||
| 46 | |||
| 47 | if (empty($exists)) { |
||
| 48 | $sql = "INSERT INTO message_rel_user (message_id, user_id, msg_read, starred, receiver_type) VALUES('$messageId', '$receiverId', 1, 0, 1) "; |
||
| 49 | $this->addSql($sql); |
||
| 50 | } |
||
| 51 | // $this->addSql("UPDATE message SET user_receiver_id = NULL WHERE id = $messageId"); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $tblMessage = $schema->getTable('message'); |
||
| 56 | |||
| 57 | if ($tblMessage->hasIndex('idx_message_user_receiver')) { |
||
| 58 | $this->addSql('DROP INDEX idx_message_user_receiver ON message'); |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($tblMessage->hasColumn('user_receiver_id')) { |
||
| 62 | $this->addSql('ALTER TABLE message DROP user_receiver_id'); |
||
| 63 | } |
||
| 64 | |||
| 65 | $newTypeQueries = []; |
||
| 66 | |||
| 67 | $newTypeQueries[] = sprintf( |
||
| 68 | 'UPDATE message SET status = %d WHERE msg_type = %d', |
||
| 69 | Message::MESSAGE_STATUS_DELETED, |
||
| 70 | self::OLD_MESSAGE_STATUS_DELETED |
||
| 71 | ); |
||
| 72 | $newTypeQueries[] = sprintf( |
||
| 73 | 'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
||
| 74 | Message::MESSAGE_TYPE_INBOX, |
||
| 75 | self::OLD_MESSAGE_STATUS_OUTBOX |
||
| 76 | ); |
||
| 77 | $newTypeQueries[] = sprintf( |
||
| 78 | 'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
||
| 79 | Message::MESSAGE_TYPE_CONVERSATION, |
||
| 80 | self::OLD_MESSAGE_STATUS_CONVERSATION |
||
| 81 | ); |
||
| 82 | |||
| 83 | $newTypeQueries[] = sprintf( |
||
| 84 | 'UPDATE message SET status = %d WHERE msg_type = %d', |
||
| 85 | Message::MESSAGE_STATUS_INVITATION_PENDING, |
||
| 86 | self::OLD_MESSAGE_STATUS_INVITATION_PENDING |
||
| 87 | ); |
||
| 88 | $newTypeQueries[] = sprintf( |
||
| 89 | 'UPDATE message SET status = %d WHERE msg_type = %d', |
||
| 90 | Message::MESSAGE_STATUS_INVITATION_ACCEPTED, |
||
| 91 | self::OLD_MESSAGE_STATUS_INVITATION_ACCEPTED |
||
| 92 | ); |
||
| 93 | $newTypeQueries[] = sprintf( |
||
| 94 | 'UPDATE message SET status = %d WHERE msg_type = %d', |
||
| 95 | Message::MESSAGE_STATUS_INVITATION_DENIED, |
||
| 96 | self::OLD_MESSAGE_STATUS_INVITATION_DENIED |
||
| 97 | ); |
||
| 98 | $newTypeQueries[] = sprintf( |
||
| 99 | 'UPDATE message SET msg_type = %d WHERE status IN (%d, %d, %d)', |
||
| 100 | Message::MESSAGE_TYPE_INVITATION, |
||
| 101 | Message::MESSAGE_STATUS_INVITATION_PENDING, |
||
| 102 | Message::MESSAGE_STATUS_INVITATION_ACCEPTED, |
||
| 103 | Message::MESSAGE_STATUS_INVITATION_DENIED |
||
| 104 | ); |
||
| 105 | |||
| 106 | $newTypeQueries[] = sprintf( |
||
| 107 | 'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
||
| 108 | Message::MESSAGE_TYPE_INBOX, |
||
| 109 | self::OLD_MESSAGE_STATUS_NEW |
||
| 110 | ); |
||
| 111 | |||
| 112 | $newTypeQueries[] = sprintf( |
||
| 113 | 'UPDATE message SET msg_type = %d WHERE group_id IS NOT NULL', |
||
| 114 | Message::MESSAGE_TYPE_GROUP |
||
| 115 | ); |
||
| 116 | |||
| 117 | foreach ($newTypeQueries as $sql) { |
||
| 118 | $this->addSql($sql); |
||
| 119 | } |
||
| 124 |