| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 214 |
| Code Lines | 125 |
| 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 |
||
| 23 | public function up(Schema $schema): void |
||
| 24 | { |
||
| 25 | $configurationValues = SettingsCurrentFixtures::getNewConfigurationSettings(); |
||
| 26 | |||
| 27 | foreach ($configurationValues as $category => $settings) { |
||
| 28 | foreach ($settings as $setting) { |
||
| 29 | $variable = $setting['name']; |
||
| 30 | $category = strtolower($category); |
||
| 31 | $result = $this->connection |
||
| 32 | ->executeQuery( |
||
| 33 | "SELECT COUNT(1) FROM settings_current WHERE variable = '$variable' AND category = '{$category}'" |
||
| 34 | ) |
||
| 35 | ; |
||
| 36 | $count = $result->fetchNumeric()[0]; |
||
| 37 | $selectedValue = $this->getConfigurationSelectedValue($variable); |
||
| 38 | error_log('Migration: Setting variable '.$variable.' category '.$category.' value '.$selectedValue); |
||
| 39 | |||
| 40 | // To use by default courses page if this option is not empty. |
||
| 41 | if ('redirect_index_to_url_for_logged_users' === $variable && !empty($selectedValue)) { |
||
| 42 | $selectedValue = 'courses'; |
||
| 43 | } |
||
| 44 | if (empty($count)) { |
||
| 45 | $this->addSql( |
||
| 46 | "INSERT INTO settings_current (access_url, variable, category, selected_value, title, access_url_changeable, access_url_locked) VALUES (1, '{$variable}', '{$category}', '{$selectedValue}', '{$variable}', 1, 1)" |
||
| 47 | ); |
||
| 48 | } else { |
||
| 49 | $this->addSql( |
||
| 50 | "UPDATE settings_current SET selected_value = '{$selectedValue}', category = '{$category}' WHERE variable = '$variable' AND category = '{$category}'" |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | // Rename setting for hierarchical skill presentation. |
||
| 57 | $this->addSql( |
||
| 58 | "UPDATE settings_current SET variable = 'skills_hierarchical_view_in_user_tracking', title = 'skills_hierarchical_view_in_user_tracking' WHERE variable = 'table_of_hierarchical_skill_presentation'" |
||
| 59 | ); |
||
| 60 | |||
| 61 | // Insert extra fields required. |
||
| 62 | $result = $this->connection |
||
| 63 | ->executeQuery( |
||
| 64 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'session_courses_read_only_mode' AND item_type = 2 AND value_type = 13" |
||
| 65 | ) |
||
| 66 | ; |
||
| 67 | $count = $result->fetchNumeric()[0]; |
||
| 68 | if (empty($count)) { |
||
| 69 | $this->addSql( |
||
| 70 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1, 1, NOW())" |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | // Insert extra fields required. |
||
| 75 | $result = $this->connection |
||
| 76 | ->executeQuery( |
||
| 77 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'is_mandatory' AND item_type = 12 AND value_type = 13" |
||
| 78 | ) |
||
| 79 | ; |
||
| 80 | $count = $result->fetchNumeric()[0]; |
||
| 81 | if (empty($count)) { |
||
| 82 | $this->addSql( |
||
| 83 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (12, 13, 'is_mandatory', 'IsMandatory', 1, 1, 1, NOW())" |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | $result = $this->connection |
||
| 88 | ->executeQuery( |
||
| 89 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'show_in_catalogue' AND item_type = 2 AND value_type = 3" |
||
| 90 | ) |
||
| 91 | ; |
||
| 92 | $count = $result->fetchNumeric()[0]; |
||
| 93 | if (empty($count)) { |
||
| 94 | $this->addSql( |
||
| 95 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (2, 3, 'show_in_catalogue', 'Show in catalogue', 1, 1, 0, NOW())" |
||
| 96 | ); |
||
| 97 | $this->addSql( |
||
| 98 | 'SET @ef_id = LAST_INSERT_ID()' |
||
| 99 | ); |
||
| 100 | $this->addSql( |
||
| 101 | "INSERT INTO extra_field_options (field_id, option_value, display_text, priority, priority_message, option_order) VALUES (@ef_id, '1', 'Yes', NULL, NULL, 1), (@ef_id, '0', 'No', NULL, NULL, 2)" |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | $result = $this->connection |
||
| 106 | ->executeQuery( |
||
| 107 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'multiple_language' AND item_type = 2 AND value_type = 5" |
||
| 108 | ) |
||
| 109 | ; |
||
| 110 | $count = $result->fetchNumeric()[0]; |
||
| 111 | if (empty($count)) { |
||
| 112 | $this->addSql( |
||
| 113 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (2, 5, 'multiple_language', 'Multiple Language', 1, 1, 1, NOW())" |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | $result = $this->connection |
||
| 118 | ->executeQuery( |
||
| 119 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'send_notification_at_a_specific_date' AND item_type = 21 AND value_type = 13" |
||
| 120 | ) |
||
| 121 | ; |
||
| 122 | $count = $result->fetchNumeric()[0]; |
||
| 123 | if (empty($count)) { |
||
| 124 | $this->addSql( |
||
| 125 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (21, 13, 'send_notification_at_a_specific_date', 'Send notification at a specific date', 1, 1, 1, NOW())" |
||
| 126 | ); |
||
| 127 | } |
||
| 128 | |||
| 129 | $result = $this->connection |
||
| 130 | ->executeQuery( |
||
| 131 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'date_to_send_notification' AND item_type = 21 AND value_type = 6" |
||
| 132 | ) |
||
| 133 | ; |
||
| 134 | $count = $result->fetchNumeric()[0]; |
||
| 135 | if (empty($count)) { |
||
| 136 | $this->addSql( |
||
| 137 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (21, 6, 'date_to_send_notification', 'Date to send notification', 1, 1, 1, NOW())" |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | $result = $this->connection |
||
| 142 | ->executeQuery( |
||
| 143 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'send_to_users_in_session' AND item_type = 21 AND value_type = 13" |
||
| 144 | ) |
||
| 145 | ; |
||
| 146 | $count = $result->fetchNumeric()[0]; |
||
| 147 | if (empty($count)) { |
||
| 148 | $this->addSql( |
||
| 149 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (21, 13, 'send_to_users_in_session', 'Send to users in session', 1, 1, 1, NOW())" |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 153 | $result = $this->connection |
||
| 154 | ->executeQuery( |
||
| 155 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'tags' AND item_type = 22 AND value_type = 10" |
||
| 156 | ) |
||
| 157 | ; |
||
| 158 | $count = $result->fetchNumeric()[0]; |
||
| 159 | if (empty($count)) { |
||
| 160 | $this->addSql( |
||
| 161 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (22, 10, 'tags', 'Tags', 1, 1, 1, NOW())" |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | |||
| 165 | $result = $this->connection |
||
| 166 | ->executeQuery( |
||
| 167 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'acquisition' AND item_type = 20 AND value_type = 3" |
||
| 168 | ) |
||
| 169 | ; |
||
| 170 | $count = $result->fetchNumeric()[0]; |
||
| 171 | if (empty($count)) { |
||
| 172 | $this->addSql( |
||
| 173 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (20, 3, 'acquisition', 'Acquisition', 1, 1, 0, NOW())" |
||
| 174 | ); |
||
| 175 | $this->addSql( |
||
| 176 | 'SET @ef_id = LAST_INSERT_ID()' |
||
| 177 | ); |
||
| 178 | $this->addSql( |
||
| 179 | "INSERT INTO extra_field_options (field_id, option_value, display_text, priority, priority_message, option_order) VALUES (@ef_id, '1', 'Acquired', NULL, NULL, 1), (@ef_id, '2', 'In the process of acquisition', NULL, NULL, 2), (@ef_id, '3', 'Not acquired', NULL, NULL, 3)" |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | |||
| 183 | $result = $this->connection |
||
| 184 | ->executeQuery( |
||
| 185 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'invisible' AND item_type = 20 AND value_type = 13" |
||
| 186 | ) |
||
| 187 | ; |
||
| 188 | $count = $result->fetchNumeric()[0]; |
||
| 189 | if (empty($count)) { |
||
| 190 | $this->addSql( |
||
| 191 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (20, 13, 'invisible', 'Invisible', 1, 1, 1, NOW())" |
||
| 192 | ); |
||
| 193 | } |
||
| 194 | |||
| 195 | $result = $this->connection |
||
| 196 | ->executeQuery( |
||
| 197 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'start_date' AND item_type = 7 AND value_type = 7" |
||
| 198 | ) |
||
| 199 | ; |
||
| 200 | $count = $result->fetchNumeric()[0]; |
||
| 201 | if (empty($count)) { |
||
| 202 | $this->addSql( |
||
| 203 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (7, 7, 'start_date', 'StartDate', 1, 1, 1, NOW())" |
||
| 204 | ); |
||
| 205 | } |
||
| 206 | |||
| 207 | $result = $this->connection |
||
| 208 | ->executeQuery( |
||
| 209 | "SELECT COUNT(1) FROM extra_field WHERE variable = 'end_date' AND item_type = 7 AND value_type = 7" |
||
| 210 | ) |
||
| 211 | ; |
||
| 212 | $count = $result->fetchNumeric()[0]; |
||
| 213 | if (empty($count)) { |
||
| 214 | $this->addSql( |
||
| 215 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (7, 7, 'end_date', 'EndDate', 1, 1, 1, NOW())" |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | |||
| 219 | $attachmentExists = $this->connection->fetchOne("SELECT COUNT(*) FROM extra_field WHERE variable = 'attachment' AND item_type = 13"); |
||
| 220 | if (0 == $attachmentExists) { |
||
| 221 | $this->addSql( |
||
| 222 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (13, 18, 'attachment', 'Attachment', 1, 1, 1, NOW())" |
||
| 223 | ); |
||
| 224 | } |
||
| 225 | |||
| 226 | $sendToCoachesExists = $this->connection->fetchOne("SELECT COUNT(*) FROM extra_field WHERE variable = 'send_to_coaches' AND item_type = 13"); |
||
| 227 | if (0 == $sendToCoachesExists) { |
||
| 228 | $this->addSql( |
||
| 229 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (13, 13, 'send_to_coaches', 'Send to Coaches', 1, 1, 1, NOW())" |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 233 | $workTimeExists = $this->connection->fetchOne("SELECT COUNT(*) FROM extra_field WHERE variable = 'work_time' AND item_type = 9"); |
||
| 234 | if (0 == $workTimeExists) { |
||
| 235 | $this->addSql( |
||
| 236 | "INSERT INTO extra_field (item_type, value_type, variable, display_text, visible_to_self, changeable, filter, created_at) VALUES (9, 15, 'work_time', 'Considered working time', 1, 1, 1, NOW())" |
||
| 237 | ); |
||
| 397 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.