| Conditions | 9 |
| Paths | 26 |
| Total Lines | 93 |
| Code Lines | 72 |
| 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 |
||
| 99 | public function update() |
||
| 100 | { |
||
| 101 | $oldCertificateTable = 'gradebook_certificate_alternative'; |
||
| 102 | $base = api_get_path(WEB_UPLOAD_PATH); |
||
|
|
|||
| 103 | if (1 == Database::num_rows(Database::query("SHOW TABLES LIKE '$oldCertificateTable'"))) { |
||
| 104 | $sql = "SELECT * FROM $oldCertificateTable"; |
||
| 105 | $res = Database::query($sql); |
||
| 106 | while ($row = Database::fetch_assoc($res)) { |
||
| 107 | $pathOrigin = $base.'certificates/'.$row['id'].'/'; |
||
| 108 | $params = [ |
||
| 109 | 'access_url_id' => api_get_current_access_url_id(), |
||
| 110 | 'c_id' => $row['c_id'], |
||
| 111 | 'session_id' => $row['session_id'], |
||
| 112 | 'content_course' => $row['content_course'], |
||
| 113 | 'contents_type' => intval($row['contents_type']), |
||
| 114 | 'contents' => $row['contents'], |
||
| 115 | 'date_change' => intval($row['date_change']), |
||
| 116 | 'date_start' => $row['date_start'], |
||
| 117 | 'date_end' => $row['date_end'], |
||
| 118 | 'place' => $row['place'], |
||
| 119 | 'type_date_expediction' => intval($row['type_date_expediction']), |
||
| 120 | 'day' => $row['day'], |
||
| 121 | 'month' => $row['month'], |
||
| 122 | 'year' => $row['year'], |
||
| 123 | 'logo_left' => $row['logo_left'], |
||
| 124 | 'logo_center' => $row['logo_center'], |
||
| 125 | 'logo_right' => $row['logo_right'], |
||
| 126 | 'seal' => $row['seal'], |
||
| 127 | 'signature1' => $row['signature1'], |
||
| 128 | 'signature2' => $row['signature2'], |
||
| 129 | 'signature3' => $row['signature3'], |
||
| 130 | 'signature4' => $row['signature4'], |
||
| 131 | 'signature_text1' => $row['signature_text1'], |
||
| 132 | 'signature_text2' => $row['signature_text2'], |
||
| 133 | 'signature_text3' => $row['signature_text3'], |
||
| 134 | 'signature_text4' => $row['signature_text4'], |
||
| 135 | 'background' => $row['background'], |
||
| 136 | 'margin_left' => intval($row['margin']), |
||
| 137 | 'margin_right' => 0, |
||
| 138 | 'certificate_default' => 0, |
||
| 139 | ]; |
||
| 140 | |||
| 141 | $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params); |
||
| 142 | |||
| 143 | // Image manager |
||
| 144 | $pathDestiny = $base.'certificates/'.$certificateId.'/'; |
||
| 145 | |||
| 146 | if (!file_exists($pathDestiny)) { |
||
| 147 | mkdir($pathDestiny, api_get_permissions_for_new_directories(), true); |
||
| 148 | } |
||
| 149 | |||
| 150 | $imgList = [ |
||
| 151 | 'logo_left', |
||
| 152 | 'logo_center', |
||
| 153 | 'logo_right', |
||
| 154 | 'seal', |
||
| 155 | 'signature1', |
||
| 156 | 'signature2', |
||
| 157 | 'signature3', |
||
| 158 | 'signature4', |
||
| 159 | 'background', |
||
| 160 | ]; |
||
| 161 | foreach ($imgList as $value) { |
||
| 162 | if (!empty($row[$value])) { |
||
| 163 | copy( |
||
| 164 | $pathOrigin.$row[$value], |
||
| 165 | $pathDestiny.$row[$value] |
||
| 166 | ); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | if (1 == $row['certificate_default']) { |
||
| 171 | $params['c_id'] = 0; |
||
| 172 | $params['session_id'] = 0; |
||
| 173 | $params['certificate_default'] = 1; |
||
| 174 | $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params); |
||
| 175 | $pathOrigin = $base.'certificates/default/'; |
||
| 176 | $pathDestiny = $base.'certificates/'.$certificateId.'/'; |
||
| 177 | foreach ($imgList as $value) { |
||
| 178 | if (!empty($row[$value])) { |
||
| 179 | copy( |
||
| 180 | $pathOrigin.$row[$value], |
||
| 181 | $pathDestiny.$row[$value] |
||
| 182 | ); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | $sql = "DROP TABLE IF EXISTS $oldCertificateTable"; |
||
| 189 | Database::query($sql); |
||
| 190 | |||
| 191 | echo get_lang('MessageUpdate'); |
||
| 192 | } |
||
| 347 |