| Conditions | 49 |
| Paths | > 20000 |
| Total Lines | 309 |
| Code Lines | 203 |
| Lines | 92 |
| Ratio | 29.77 % |
| 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 |
||
| 17 | function maj_v014_dist($version_installee, $version_cible) |
||
| 18 | { |
||
| 19 | View Code Duplication | if (upgrade_vers(1.404, $version_installee, $version_cible)) { |
|
|
|
|||
| 20 | spip_query("UPDATE spip_mots SET type='Mots sans groupe...' WHERE type=''"); |
||
| 21 | |||
| 22 | $result = spip_query("SELECT * FROM spip_mots GROUP BY type"); |
||
| 23 | while($row = sql_fetch($result)) { |
||
| 24 | $type = addslashes($row['type']); |
||
| 25 | // Old style, doit echouer |
||
| 26 | spip_log('ne pas tenir compte de l erreur spip_groupes_mots ci-dessous:', 'mysql'); |
||
| 27 | spip_query("INSERT INTO spip_groupes_mots (titre, unseul, obligatoire, articles, breves, rubriques, syndic, 0minirezo, 1comite, 6forum) VALUES (\"$type\", 'non', 'non', 'oui', 'oui', 'non', 'oui', 'oui', 'oui', 'non')"); |
||
| 28 | // New style, devrait marcher |
||
| 29 | spip_query("INSERT INTO spip_groupes_mots (titre, unseul, obligatoire, articles, breves, rubriques, syndic, minirezo, comite, forum) VALUES (\"$type\", 'non', 'non', 'oui', 'oui', 'non', 'oui', 'oui', 'oui', 'non')"); |
||
| 30 | } |
||
| 31 | sql_delete("spip_mots", "titre='kawax'"); |
||
| 32 | maj_version (1.404); |
||
| 33 | } |
||
| 34 | |||
| 35 | View Code Duplication | if (upgrade_vers(1.405, $version_installee, $version_cible)) { |
|
| 36 | spip_query("ALTER TABLE spip_mots ADD id_groupe bigint(21) NOT NULL"); |
||
| 37 | |||
| 38 | $result = spip_query("SELECT * FROM spip_groupes_mots"); |
||
| 39 | while($row = sql_fetch($result)) { |
||
| 40 | $id_groupe = addslashes($row['id_groupe']); |
||
| 41 | $type = addslashes($row['titre']); |
||
| 42 | spip_query("UPDATE spip_mots SET id_groupe = '$id_groupe' WHERE type='$type'"); |
||
| 43 | } |
||
| 44 | maj_version (1.405); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (upgrade_vers(1.408, $version_installee, $version_cible)) { |
||
| 48 | // Images articles passent dans spip_documents |
||
| 49 | $result = spip_query("SELECT id_article, images FROM spip_articles WHERE LENGTH(images) > 0"); |
||
| 50 | |||
| 51 | |||
| 52 | $types = array('jpg' => 1, 'png' => 2, 'gif' => 3); |
||
| 53 | |||
| 54 | while ($row = @sql_fetch($result)) { |
||
| 55 | $id_article = $row['id_article']; |
||
| 56 | $images = $row['images']; |
||
| 57 | $images = explode(",", $images); |
||
| 58 | reset($images); |
||
| 59 | $replace = '_orig_'; |
||
| 60 | foreach ($images as $val) { |
||
| 61 | $image = explode("|", $val); |
||
| 62 | $fichier = $image[0]; |
||
| 63 | $largeur = $image[1]; |
||
| 64 | $hauteur = $image[2]; |
||
| 65 | preg_match(",-([0-9]+)\.(gif|jpg|png)$,i", $fichier, $match); |
||
| 66 | $id_type = intval($types[$match[2]]); |
||
| 67 | $num_img = $match[1]; |
||
| 68 | $fichier = _DIR_IMG . $fichier; |
||
| 69 | $taille = @filesize($fichier); |
||
| 70 | // ici on n'a pas les fonctions absctract ! |
||
| 71 | $s = spip_query("INSERT INTO spip_documents (titre, id_type, fichier, mode, largeur, hauteur, taille) VALUES ('image $largeur x $hauteur', $id_type, '$fichier', 'vignette', '$largeur', '$hauteur', '$taille')"); |
||
| 72 | $id_document = mysql_insert_id($s); |
||
| 73 | if ($id_document > 0) { |
||
| 74 | spip_query("INSERT INTO spip_documents_articles (id_document, id_article) VALUES ($id_document, $id_article)"); |
||
| 75 | $replace = "REPLACE($replace, '<IMG$num_img|', '<IM_$id_document|')"; |
||
| 76 | } else { |
||
| 77 | echo _T('texte_erreur_mise_niveau_base', array('fichier' => $fichier, 'id_article' => $id_article)); |
||
| 78 | exit; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | $replace = "REPLACE($replace, '<IM_', '<IMG')"; |
||
| 82 | $replace_chapo = str_replace('_orig_', 'chapo', $replace); |
||
| 83 | $replace_descriptif = str_replace('_orig_', 'descriptif', $replace); |
||
| 84 | $replace_texte = str_replace('_orig_', 'texte', $replace); |
||
| 85 | $replace_ps = str_replace('_orig_', 'ps', $replace); |
||
| 86 | spip_query("UPDATE spip_articles SET chapo=$replace_chapo, descriptif=$replace_descriptif, texte=$replace_texte, ps=$replace_ps WHERE id_article=$id_article"); |
||
| 87 | |||
| 88 | } |
||
| 89 | spip_query("ALTER TABLE spip_articles DROP images"); |
||
| 90 | maj_version (1.408); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (upgrade_vers(1.414, $version_installee, $version_cible)) { |
||
| 94 | // Forum par defaut "en dur" dans les spip_articles |
||
| 95 | // -> non, prio (priori), pos (posteriori), abo (abonnement) |
||
| 96 | $accepter_forum = substr($GLOBALS['meta']["forums_publics"],0,3) ; |
||
| 97 | $result = spip_query("ALTER TABLE spip_articles CHANGE accepter_forum accepter_forum CHAR(3) NOT NULL"); |
||
| 98 | |||
| 99 | $result = spip_query("UPDATE spip_articles SET accepter_forum='$accepter_forum' WHERE accepter_forum != 'non'"); |
||
| 100 | |||
| 101 | maj_version (1.414); |
||
| 102 | } |
||
| 103 | |||
| 104 | /* |
||
| 105 | if ($version_installee == 1.415) { |
||
| 106 | spip_query("ALTER TABLE spip_documents DROP inclus"); |
||
| 107 | maj_version (1.415); |
||
| 108 | } |
||
| 109 | */ |
||
| 110 | |||
| 111 | if (upgrade_vers(1.417, $version_installee, $version_cible)) { |
||
| 112 | spip_query("ALTER TABLE spip_syndic_articles DROP date_index"); |
||
| 113 | maj_version (1.417); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (upgrade_vers(1.418, $version_installee, $version_cible)) { |
||
| 117 | $result = spip_query("SELECT * FROM spip_auteurs WHERE statut = '0minirezo' AND email != '' ORDER BY id_auteur LIMIT 1"); |
||
| 118 | |||
| 119 | if ($webmaster = sql_fetch($result)) { |
||
| 120 | ecrire_meta('email_webmaster', $webmaster['email']); |
||
| 121 | } |
||
| 122 | maj_version (1.418); |
||
| 123 | } |
||
| 124 | |||
| 125 | View Code Duplication | if (upgrade_vers(1.419, $version_installee, $version_cible)) { |
|
| 126 | spip_query("ALTER TABLE spip_auteurs ADD alea_actuel TINYTEXT DEFAULT ''"); |
||
| 127 | spip_query("ALTER TABLE spip_auteurs ADD alea_futur TINYTEXT DEFAULT ''"); |
||
| 128 | spip_query("UPDATE spip_auteurs SET alea_futur = FLOOR(32000*RAND())"); |
||
| 129 | maj_version (1.419); |
||
| 130 | } |
||
| 131 | |||
| 132 | if (upgrade_vers(1.420, $version_installee, $version_cible)) { |
||
| 133 | spip_query("UPDATE spip_auteurs SET alea_actuel='' WHERE statut='nouveau'"); |
||
| 134 | maj_version (1.420); |
||
| 135 | } |
||
| 136 | |||
| 137 | if (upgrade_vers(1.421, $version_installee, $version_cible)) { |
||
| 138 | spip_query("ALTER TABLE spip_articles ADD auteur_modif bigint(21) DEFAULT '0' NOT NULL"); |
||
| 139 | spip_query("ALTER TABLE spip_articles ADD date_modif datetime DEFAULT '0000-00-00 00:00:00' NOT NULL"); |
||
| 140 | maj_version (1.421); |
||
| 141 | } |
||
| 142 | |||
| 143 | View Code Duplication | if (upgrade_vers(1.432, $version_installee, $version_cible)) { |
|
| 144 | spip_query("ALTER TABLE spip_articles DROP referers"); |
||
| 145 | spip_query("ALTER TABLE spip_articles ADD referers INTEGER DEFAULT '0' NOT NULL"); |
||
| 146 | spip_query("ALTER TABLE spip_articles ADD popularite INTEGER DEFAULT '0' NOT NULL"); |
||
| 147 | maj_version (1.432); |
||
| 148 | } |
||
| 149 | |||
| 150 | if (upgrade_vers(1.436, $version_installee, $version_cible)) { |
||
| 151 | spip_query("ALTER TABLE spip_documents ADD date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL"); |
||
| 152 | maj_version (1.436); |
||
| 153 | } |
||
| 154 | |||
| 155 | if (upgrade_vers(1.437, $version_installee, $version_cible)) { |
||
| 156 | spip_query("ALTER TABLE spip_visites ADD maj TIMESTAMP"); |
||
| 157 | spip_query("ALTER TABLE spip_visites_referers ADD maj TIMESTAMP"); |
||
| 158 | maj_version (1.437); |
||
| 159 | } |
||
| 160 | |||
| 161 | if (upgrade_vers(1.438, $version_installee, $version_cible)) { |
||
| 162 | spip_query("ALTER TABLE spip_articles ADD INDEX id_secteur (id_secteur)"); |
||
| 163 | spip_query("ALTER TABLE spip_articles ADD INDEX statut (statut, date)"); |
||
| 164 | maj_version (1.438); |
||
| 165 | } |
||
| 166 | |||
| 167 | View Code Duplication | if (upgrade_vers(1.439, $version_installee, $version_cible)) { |
|
| 168 | spip_query("ALTER TABLE spip_syndic ADD INDEX statut (statut, date_syndic)"); |
||
| 169 | spip_query("ALTER TABLE spip_syndic_articles ADD INDEX statut (statut)"); |
||
| 170 | spip_query("ALTER TABLE spip_syndic_articles CHANGE url url VARCHAR(255) NOT NULL"); |
||
| 171 | spip_query("ALTER TABLE spip_syndic_articles ADD INDEX url (url)"); |
||
| 172 | maj_version (1.439); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (upgrade_vers(1.440, $version_installee, $version_cible)) { |
||
| 176 | spip_query("ALTER TABLE spip_visites_temp CHANGE ip ip INTEGER UNSIGNED NOT NULL"); |
||
| 177 | maj_version (1.440); |
||
| 178 | } |
||
| 179 | |||
| 180 | View Code Duplication | if (upgrade_vers(1.441, $version_installee, $version_cible)) { |
|
| 181 | spip_query("ALTER TABLE spip_visites_temp CHANGE date date DATE NOT NULL"); |
||
| 182 | spip_query("ALTER TABLE spip_visites CHANGE date date DATE NOT NULL"); |
||
| 183 | spip_query("ALTER TABLE spip_visites_referers CHANGE date date DATE NOT NULL"); |
||
| 184 | maj_version (1.441); |
||
| 185 | } |
||
| 186 | |||
| 187 | if (upgrade_vers(1.442, $version_installee, $version_cible)) { |
||
| 188 | spip_query("ALTER TABLE spip_auteurs ADD prefs TINYTEXT NOT NULL"); |
||
| 189 | maj_version (1.442); |
||
| 190 | } |
||
| 191 | |||
| 192 | View Code Duplication | if (upgrade_vers(1.443, $version_installee, $version_cible)) { |
|
| 193 | spip_query("ALTER TABLE spip_auteurs CHANGE login login VARCHAR(255) BINARY NOT NULL"); |
||
| 194 | spip_query("ALTER TABLE spip_auteurs CHANGE statut statut VARCHAR(255) NOT NULL"); |
||
| 195 | spip_query("ALTER TABLE spip_auteurs ADD INDEX login (login)"); |
||
| 196 | spip_query("ALTER TABLE spip_auteurs ADD INDEX statut (statut)"); |
||
| 197 | maj_version (1.443); |
||
| 198 | } |
||
| 199 | |||
| 200 | if (upgrade_vers(1.444, $version_installee, $version_cible)) { |
||
| 201 | spip_query("ALTER TABLE spip_syndic ADD moderation VARCHAR(3) NOT NULL"); |
||
| 202 | maj_version (1.444); |
||
| 203 | } |
||
| 204 | |||
| 205 | View Code Duplication | if (upgrade_vers(1.457, $version_installee, $version_cible)) { |
|
| 206 | spip_query("DROP TABLE spip_visites"); |
||
| 207 | spip_query("DROP TABLE spip_visites_temp"); |
||
| 208 | spip_query("DROP TABLE spip_visites_referers"); |
||
| 209 | creer_base(); // crade, a ameliorer :-(( |
||
| 210 | maj_version (1.457); |
||
| 211 | } |
||
| 212 | |||
| 213 | if (upgrade_vers(1.458, $version_installee, $version_cible)) { |
||
| 214 | spip_query("ALTER TABLE spip_auteurs ADD cookie_oubli TINYTEXT NOT NULL"); |
||
| 215 | maj_version (1.458); |
||
| 216 | } |
||
| 217 | |||
| 218 | if (upgrade_vers(1.459, $version_installee, $version_cible)) { |
||
| 219 | $result = spip_query("SELECT type FROM spip_mots GROUP BY type"); |
||
| 220 | while ($row = sql_fetch($result)) { |
||
| 221 | $type = addslashes($row['type']); |
||
| 222 | $res = spip_query("SELECT * FROM spip_groupes_mots WHERE titre='$type'"); |
||
| 223 | if (sql_count($res) == 0) { |
||
| 224 | $s = spip_query("INSERT INTO spip_groupes_mots (titre, unseul, obligatoire, articles, breves, rubriques, syndic, minirezo, comite, forum) VALUES ('$type', 'non', 'non', 'oui', 'oui', 'non', 'oui', 'oui', 'oui', 'non')"); |
||
| 225 | if ($id_groupe = mysql_insert_id($s)) |
||
| 226 | spip_query("UPDATE spip_mots SET id_groupe = '$id_groupe' WHERE type='$type'"); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | spip_query("UPDATE spip_articles SET popularite=0"); |
||
| 230 | maj_version (1.459); |
||
| 231 | } |
||
| 232 | |||
| 233 | if (upgrade_vers(1.460, $version_installee, $version_cible)) { |
||
| 234 | // remettre les mots dans les groupes dupliques par erreur |
||
| 235 | // dans la precedente version du paragraphe de maj 1.459 |
||
| 236 | // et supprimer ceux-ci |
||
| 237 | $result = spip_query("SELECT * FROM spip_groupes_mots ORDER BY id_groupe"); |
||
| 238 | while ($row = sql_fetch($result)) { |
||
| 239 | $titre = addslashes($row['titre']); |
||
| 240 | if (! $vu[$titre] ) { |
||
| 241 | $vu[$titre] = true; |
||
| 242 | $id_groupe = $row['id_groupe']; |
||
| 243 | spip_query("UPDATE spip_mots SET id_groupe=$id_groupe WHERE type='$titre'"); |
||
| 244 | sql_delete("spip_groupes_mots", "titre='$titre' AND id_groupe<>$id_groupe"); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | maj_version (1.460); |
||
| 248 | } |
||
| 249 | |||
| 250 | if (upgrade_vers(1.462, $version_installee, $version_cible)) { |
||
| 251 | spip_query("UPDATE spip_types_documents SET inclus='embed' WHERE inclus!='non' AND extension IN ('aiff', 'asf', 'avi', 'mid', 'mov', 'mp3', 'mpg', 'ogg', 'qt', 'ra', 'ram', 'rm', 'swf', 'wav', 'wmv')"); |
||
| 252 | maj_version (1.462); |
||
| 253 | } |
||
| 254 | |||
| 255 | View Code Duplication | if (upgrade_vers(1.463, $version_installee, $version_cible)) { |
|
| 256 | spip_query("ALTER TABLE spip_articles CHANGE popularite popularite DOUBLE"); |
||
| 257 | spip_query("ALTER TABLE spip_visites_temp ADD maj TIMESTAMP"); |
||
| 258 | spip_query("ALTER TABLE spip_referers_temp ADD maj TIMESTAMP"); |
||
| 259 | maj_version (1.463); |
||
| 260 | } |
||
| 261 | |||
| 262 | // l'upgrade < 1.462 ci-dessus etait fausse, d'ou correctif |
||
| 263 | if (upgrade_vers(1.464, $version_installee, $version_cible) AND ($version_installee >= 1.462)) { |
||
| 264 | $res = spip_query("SELECT id_type, extension FROM spip_types_documents WHERE id_type NOT IN (1,2,3)"); |
||
| 265 | while ($row = sql_fetch($res)) { |
||
| 266 | $extension = $row['extension']; |
||
| 267 | $id_type = $row['id_type']; |
||
| 268 | spip_query("UPDATE spip_documents SET id_type=$id_type WHERE fichier like '%.$extension'"); |
||
| 269 | } |
||
| 270 | maj_version (1.464); |
||
| 271 | } |
||
| 272 | |||
| 273 | if (upgrade_vers(1.465, $version_installee, $version_cible)) { |
||
| 274 | spip_query("ALTER TABLE spip_articles CHANGE popularite popularite DOUBLE NOT NULL"); |
||
| 275 | maj_version (1.465); |
||
| 276 | } |
||
| 277 | |||
| 278 | if (upgrade_vers(1.466, $version_installee, $version_cible)) { |
||
| 279 | spip_query("ALTER TABLE spip_auteurs ADD source VARCHAR(10) DEFAULT 'spip' NOT NULL"); |
||
| 280 | maj_version (1.466); |
||
| 281 | } |
||
| 282 | |||
| 283 | if (upgrade_vers(1.468, $version_installee, $version_cible)) { |
||
| 284 | spip_query("ALTER TABLE spip_auteurs ADD INDEX en_ligne (en_ligne)"); |
||
| 285 | spip_query("ALTER TABLE spip_forum ADD INDEX statut (statut, date_heure)"); |
||
| 286 | maj_version (1.468); |
||
| 287 | } |
||
| 288 | |||
| 289 | View Code Duplication | if (upgrade_vers(1.470, $version_installee, $version_cible)) { |
|
| 290 | if ($version_installee >= 1.467) { // annule les "listes de diff" |
||
| 291 | spip_query("DROP TABLE spip_listes"); |
||
| 292 | spip_query("ALTER TABLE spip_auteurs DROP abonne"); |
||
| 293 | spip_query("ALTER TABLE spip_auteurs DROP abonne_pass"); |
||
| 294 | } |
||
| 295 | maj_version (1.470); |
||
| 296 | } |
||
| 297 | |||
| 298 | if (upgrade_vers(1.471, $version_installee, $version_cible)) { |
||
| 299 | View Code Duplication | if ($version_installee >= 1.470) { // annule les "maj" |
|
| 300 | spip_query("ALTER TABLE spip_auteurs_articles DROP maj TIMESTAMP"); |
||
| 301 | spip_query("ALTER TABLE spip_auteurs_rubriques DROP maj TIMESTAMP"); |
||
| 302 | spip_query("ALTER TABLE spip_auteurs_messages DROP maj TIMESTAMP"); |
||
| 303 | spip_query("ALTER TABLE spip_documents_articles DROP maj TIMESTAMP"); |
||
| 304 | spip_query("ALTER TABLE spip_documents_rubriques DROP maj TIMESTAMP"); |
||
| 305 | spip_query("ALTER TABLE spip_documents_breves DROP maj TIMESTAMP"); |
||
| 306 | spip_query("ALTER TABLE spip_mots_articles DROP maj TIMESTAMP"); |
||
| 307 | spip_query("ALTER TABLE spip_mots_breves DROP maj TIMESTAMP"); |
||
| 308 | spip_query("ALTER TABLE spip_mots_rubriques DROP maj TIMESTAMP"); |
||
| 309 | spip_query("ALTER TABLE spip_mots_syndic DROP maj TIMESTAMP"); |
||
| 310 | spip_query("ALTER TABLE spip_mots_forum DROP maj TIMESTAMP"); |
||
| 311 | } |
||
| 312 | maj_version (1.471); |
||
| 313 | } |
||
| 314 | |||
| 315 | if (upgrade_vers(1.472, $version_installee, $version_cible)) { |
||
| 316 | spip_query("ALTER TABLE spip_referers ADD visites_jour INTEGER UNSIGNED NOT NULL"); |
||
| 317 | maj_version (1.472); |
||
| 318 | } |
||
| 319 | |||
| 320 | if (upgrade_vers(1.473, $version_installee, $version_cible)) { |
||
| 321 | spip_query("UPDATE spip_syndic_articles SET url = REPLACE(url, '&', '&')"); |
||
| 322 | spip_query("UPDATE spip_syndic SET url_site = REPLACE(url_site, '&', '&')"); |
||
| 323 | maj_version (1.473); |
||
| 324 | } |
||
| 325 | } |
||
| 326 | |||
| 329 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.