| Conditions | 5 |
| Paths | 9 |
| Total Lines | 216 |
| Code Lines | 142 |
| 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 |
||
| 19 | public function up(Schema $schema) |
||
| 20 | { |
||
| 21 | error_log('Version20160907140300'); |
||
| 22 | $data = [ |
||
| 23 | 'career' => [ |
||
| 24 | 'created_at', |
||
| 25 | 'updated_at', |
||
| 26 | ], |
||
| 27 | 'chat' => [ |
||
| 28 | 'sent', |
||
| 29 | |||
| 30 | ], |
||
| 31 | 'course' => [ |
||
| 32 | 'last_visit', |
||
| 33 | 'last_edit', |
||
| 34 | 'creation_date', |
||
| 35 | 'expiration_date', |
||
| 36 | ], |
||
| 37 | 'course_request' => [ |
||
| 38 | 'request_date', |
||
| 39 | ], |
||
| 40 | 'gradebook_certificate' => [ |
||
| 41 | 'created_at', |
||
| 42 | ], |
||
| 43 | 'gradebook_evaluation' => [ |
||
| 44 | 'created_at', |
||
| 45 | ], |
||
| 46 | 'gradebook_link' => [ |
||
| 47 | 'created_at', |
||
| 48 | ], |
||
| 49 | 'gradebook_linkeval_log' => [ |
||
| 50 | 'created_at', |
||
| 51 | ], |
||
| 52 | 'gradebook_result' => [ |
||
| 53 | 'created_at', |
||
| 54 | ], |
||
| 55 | 'gradebook_result_log' => [ |
||
| 56 | 'created_at', |
||
| 57 | ], |
||
| 58 | 'message' => [ |
||
| 59 | 'send_date', |
||
| 60 | ], |
||
| 61 | 'notification' => [ |
||
| 62 | 'sent_at' |
||
| 63 | ], |
||
| 64 | 'promotion' => [ |
||
| 65 | 'created_at', |
||
| 66 | 'updated_at', |
||
| 67 | ], |
||
| 68 | 'shared_survey' => [ |
||
| 69 | 'creation_date', |
||
| 70 | ], |
||
| 71 | 'sequence_value' => [ |
||
| 72 | 'success_date', |
||
| 73 | 'available_start_date', |
||
| 74 | 'available_end_date', |
||
| 75 | ], |
||
| 76 | 'session_rel_user' => [ |
||
| 77 | 'moved_at', |
||
| 78 | 'registered_at', |
||
| 79 | ], |
||
| 80 | 'skill' => [ |
||
| 81 | 'updated_at', |
||
| 82 | ], |
||
| 83 | 'sys_announcement' => [ |
||
| 84 | 'date_start', |
||
| 85 | 'date_end', |
||
| 86 | ], |
||
| 87 | 'track_e_attempt_recording' => [ |
||
| 88 | 'insert_date', |
||
| 89 | |||
| 90 | ], |
||
| 91 | 'track_e_course_access' => [ |
||
| 92 | 'login_course_date', |
||
| 93 | 'logout_course_date', |
||
| 94 | ], |
||
| 95 | 'track_e_downloads' => [ |
||
| 96 | 'down_date', |
||
| 97 | ], |
||
| 98 | 'track_e_exercises' => [ |
||
| 99 | 'start_date', |
||
| 100 | 'exe_date', |
||
| 101 | ], |
||
| 102 | 'track_e_hotpotatoes' => [ |
||
| 103 | 'exe_date', |
||
| 104 | ], |
||
| 105 | 'track_e_item_property' => [ |
||
| 106 | 'lastedit_date', |
||
| 107 | ], |
||
| 108 | 'track_e_links' => [ |
||
| 109 | 'links_date', |
||
| 110 | ], |
||
| 111 | 'track_e_login' => [ |
||
| 112 | 'logout_date', |
||
| 113 | ], |
||
| 114 | 'track_e_online' => [ |
||
| 115 | 'login_date', |
||
| 116 | ], |
||
| 117 | 'track_e_open' => [ |
||
| 118 | 'open_date', |
||
| 119 | ], |
||
| 120 | 'track_e_uploads' => [ |
||
| 121 | 'upload_date', |
||
| 122 | ], |
||
| 123 | 'user_api_key' => [ |
||
| 124 | 'created_date', |
||
| 125 | 'validity_start_date', |
||
| 126 | 'validity_end_date', |
||
| 127 | ], |
||
| 128 | 'user_rel_user' => [ |
||
| 129 | 'last_edit', |
||
| 130 | ], |
||
| 131 | 'c_attendance_calendar' => [ |
||
| 132 | 'date_time', |
||
| 133 | ], |
||
| 134 | 'c_attendance_sheet_log' => [ |
||
| 135 | 'calendar_date_value', |
||
| 136 | ], |
||
| 137 | 'c_blog' => [ |
||
| 138 | 'date_creation', |
||
| 139 | ], |
||
| 140 | 'c_blog_comment' => [ |
||
| 141 | 'date_creation', |
||
| 142 | ], |
||
| 143 | 'c_blog_post' => [ |
||
| 144 | 'date_creation', |
||
| 145 | ], |
||
| 146 | 'c_blog_task_rel_user' => [ |
||
| 147 | 'target_date', |
||
| 148 | ], |
||
| 149 | 'c_chat_connected' => [ |
||
| 150 | 'last_connection', |
||
| 151 | ], |
||
| 152 | 'c_dropbox_feedback' => [ |
||
| 153 | 'feedback_date', |
||
| 154 | ], |
||
| 155 | 'c_dropbox_file' => [ |
||
| 156 | 'upload_date', |
||
| 157 | 'last_upload_date', |
||
| 158 | ], |
||
| 159 | 'c_dropbox_post' => [ |
||
| 160 | 'feedback_date', |
||
| 161 | ], |
||
| 162 | 'c_forum_post' => [ |
||
| 163 | 'post_date', |
||
| 164 | ], |
||
| 165 | 'c_forum_thread' => [ |
||
| 166 | 'thread_date', |
||
| 167 | 'thread_close_date', |
||
| 168 | ], |
||
| 169 | 'c_forum_thread_qualify' => [ |
||
| 170 | 'qualify_time', |
||
| 171 | ], |
||
| 172 | 'c_forum_thread_qualify_log' => [ |
||
| 173 | 'qualify_time', |
||
| 174 | ], |
||
| 175 | 'c_lp' => [ |
||
| 176 | 'created_on', |
||
| 177 | 'modified_on', |
||
| 178 | ], |
||
| 179 | 'c_notebook' => [ |
||
| 180 | 'creation_date', |
||
| 181 | 'update_date', |
||
| 182 | ], |
||
| 183 | 'c_online_connected' => [ |
||
| 184 | 'last_connection', |
||
| 185 | ], |
||
| 186 | 'c_survey' => [ |
||
| 187 | 'creation_date', |
||
| 188 | ], |
||
| 189 | 'c_survey_invitation' => [ |
||
| 190 | 'invitation_date', |
||
| 191 | 'reminder_date', |
||
| 192 | ], |
||
| 193 | 'c_userinfo_content' => [ |
||
| 194 | 'edition_time' |
||
| 195 | ], |
||
| 196 | 'c_wiki_discuss' => [ |
||
| 197 | 'dtime', |
||
| 198 | ], |
||
| 199 | |||
| 200 | ]; |
||
| 201 | // Needed to update 0000-00-00 00:00:00 values |
||
| 202 | $this->addSql('SET sql_mode = ""'); |
||
| 203 | // In case this one didn't work, also try this |
||
| 204 | $this->addSql('SET SESSION sql_mode = ""'); |
||
| 205 | |||
| 206 | // The whole point of this version is to ensure that all tricky (or most) |
||
| 207 | // tricky datetime fields are null if = 0000-00-00 00:00:00, because |
||
| 208 | // this value is not tolerated in NO_ZERO_DATE mode nor to convert |
||
| 209 | // the table to InnoDB, and we want all tables to be converted to |
||
| 210 | // InnoDB (that's the point of the following migration) |
||
| 211 | // To try and avoid errors to the maximum, we first convert the fields |
||
| 212 | // to a non-DATETIME type, then change the value of zero-valued times |
||
| 213 | // to NULL, then change the field back to DATETIME |
||
| 214 | foreach ($data as $table => $fields) { |
||
| 215 | foreach ($fields as $field) { |
||
| 216 | error_log("$table . $field"); |
||
| 217 | $this->addSql("ALTER TABLE $table CHANGE $field $field char(19)"); |
||
| 218 | $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00 00:00:00'"); |
||
| 219 | $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00 23:59:59'"); |
||
| 220 | $this->addSql("ALTER TABLE $table CHANGE $field $field DATETIME"); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | // Same with DATE instead of DATETIME |
||
| 224 | $data = [ |
||
| 225 | 'c_announcement' => [ |
||
| 226 | 'end_date', |
||
| 227 | ], |
||
| 228 | ]; |
||
| 229 | foreach ($data as $table => $fields) { |
||
| 230 | foreach ($fields as $field) { |
||
| 231 | error_log("$table . $field"); |
||
| 232 | $this->addSql("ALTER TABLE $table CHANGE $field $field char(10)"); |
||
| 233 | $this->addSql("UPDATE $table SET $field = NULL WHERE $field = '0000-00-00'"); |
||
| 234 | $this->addSql("ALTER TABLE $table CHANGE $field $field DATE"); |
||
| 235 | } |
||
| 243 |