| Conditions | 13 |
| Paths | 1600 |
| Total Lines | 97 |
| Code Lines | 66 |
| Lines | 45 |
| Ratio | 46.39 % |
| 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 |
||
| 18 | function exec_menu_navigation_dist() { |
||
| 19 | global $connect_id_auteur, $spip_lang_left; |
||
| 20 | |||
| 21 | $id_rubrique = intval(_request('id_rubrique')); |
||
| 22 | |||
| 23 | $gadget = '<div style="width: 300px;">'; |
||
| 24 | |||
| 25 | $vos_articles = sql_select("articles.id_article, articles.id_rubrique, articles.titre, articles.statut", "spip_articles AS articles, spip_auteurs_articles AS lien", "articles.id_article=lien.id_article AND lien.id_auteur=$connect_id_auteur AND articles.statut='prepa'", "articles.date", "articles.date DESC", "5"); |
||
| 26 | $vos = ''; |
||
| 27 | View Code Duplication | while($row = sql_fetch($vos_articles)) { |
|
|
|
|||
| 28 | $id_article = $row['id_article']; |
||
| 29 | $titre = typo(sinon($row['titre'], _T('ecrire:info_sans_titre'))); |
||
| 30 | $statut = $row['statut']; |
||
| 31 | $h = generer_url_ecrire("articles","id_article=$id_article"); |
||
| 32 | $vos .= "<a class='$statut spip_xx-small' href='$h'>$titre</a>\n"; |
||
| 33 | } |
||
| 34 | View Code Duplication | if ($vos) { |
|
| 35 | $t = _T('info_en_cours_validation'); |
||
| 36 | $gadget .= debut_cadre('bandeau-rubriques',"article-24.gif",'',afficher_plus(generer_url_ecrire("articles_page")).$t) |
||
| 37 | . "\n<div class='plan-articles'>\n" |
||
| 38 | . $vos |
||
| 39 | . "</div>" |
||
| 40 | . fin_cadre('bandeau-rubriques'); |
||
| 41 | } |
||
| 42 | |||
| 43 | $vos_articles = sql_select("id_article, id_rubrique, titre, statut", "spip_articles", "statut='prop'", "date", "date DESC", "5"); |
||
| 44 | $vos = ''; |
||
| 45 | View Code Duplication | while($row = sql_fetch($vos_articles)) { |
|
| 46 | $id_article = $row['id_article']; |
||
| 47 | $titre = sinon($row['titre'], _T('ecrire:info_sans_titre')); |
||
| 48 | $statut = $row['statut']; |
||
| 49 | $h = generer_url_ecrire("articles","id_article=$id_article"); |
||
| 50 | $vos .= "<a class='$statut' href='$h'>$titre</a>"; |
||
| 51 | } |
||
| 52 | View Code Duplication | if ($vos) { |
|
| 53 | $gadget .= debut_cadre('bandeau-rubriques',"article-24.gif",'',afficher_plus(generer_url_ecrire())._T('info_articles_proposes')) |
||
| 54 | . "<div class='plan-articles'>" |
||
| 55 | . $vos |
||
| 56 | . "</div>" |
||
| 57 | . fin_cadre('bandeau-rubriques'); |
||
| 58 | } |
||
| 59 | |||
| 60 | $vos_articles = sql_select("id_breve,titre,statut", "spip_breves", "statut='prop'", "date_heure", "date_heure DESC", "5"); |
||
| 61 | $vos = ''; |
||
| 62 | while($row = sql_fetch($vos_articles)) { |
||
| 63 | $id_breve = $row['id_breve']; |
||
| 64 | $titre = typo(sinon($row['titre'], _T('ecrire:info_sans_titre'))); |
||
| 65 | $statut = $row['statut']; |
||
| 66 | $vos .= "<a class='$statut spip_xx-small' href='" . generer_url_ecrire("breves_voir","id_breve=$id_breve") . "'>$titre</a>"; |
||
| 67 | } |
||
| 68 | View Code Duplication | if ($vos) { |
|
| 69 | $gadget .= debut_cadre('bandeau-rubriques',"breve-24.gif",'',afficher_plus(generer_url_ecrire("breves"))._T('info_breves_valider')) |
||
| 70 | . "<div class='plan-articles'>" |
||
| 71 | . $vos |
||
| 72 | . "</div>" |
||
| 73 | . fin_cadre('bandeau-rubriques'); |
||
| 74 | } |
||
| 75 | |||
| 76 | $une_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', '','','', 1); |
||
| 77 | if ($une_rubrique) { |
||
| 78 | |||
| 79 | $gadget .= "<div> </div>"; |
||
| 80 | View Code Duplication | if ($id_rubrique > 0) { |
|
| 81 | $dans_rub = "&id_rubrique=$id_rubrique"; |
||
| 82 | $dans_parent = "&id_parent=$id_rubrique"; |
||
| 83 | } else $dans_rub = $dans_parent = ''; |
||
| 84 | if (autoriser('creerrubriquedans', 'rubrique', $id_rubrique)) { |
||
| 85 | # $gadget .= "<div style='width: 140px; float: $spip_lang_left;'>"; |
||
| 86 | if ($id_rubrique > 0) |
||
| 87 | $gadget .= icone_horizontale_display(_T('icone_creer_sous_rubrique'), generer_url_ecrire("rubriques_edit","new=oui$dans_parent"), "rubrique-24.gif", "creer.gif", false); |
||
| 88 | else |
||
| 89 | $gadget .= icone_horizontale_display(_T('icone_creer_rubrique'), generer_url_ecrire("rubriques_edit","new=oui"), "rubrique-24.gif", "creer.gif", false); |
||
| 90 | # $gadget .= "</div>"; |
||
| 91 | } |
||
| 92 | # $gadget .= "<div style='width: 140px; float: $spip_lang_left;'>"; |
||
| 93 | $gadget .= icone_horizontale_display(_T('icone_ecrire_article'), generer_url_ecrire("articles_edit","new=oui$dans_rub"), "article-24.gif","creer.gif", false); |
||
| 94 | # $gadget .= "</div>"; |
||
| 95 | |||
| 96 | View Code Duplication | if ($GLOBALS['meta']["activer_breves"] != "non") { |
|
| 97 | # $gadget .= "<div style='width: 140px; float: $spip_lang_left;'>"; |
||
| 98 | $gadget .= icone_horizontale_display(_T('icone_nouvelle_breve'), generer_url_ecrire("breves_edit","new=oui$dans_rub"), "breve-24.gif","creer.gif", false); |
||
| 99 | # $gadget .= "</div>"; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (autoriser('creersitedans', 'rubrique', $une_rubrique)) { |
||
| 103 | $gadget .= # "<div style='width: 140px; float: $spip_lang_left;'>" . |
||
| 104 | icone_horizontale_display(_T('info_sites_referencer'), generer_url_ecrire("sites_edit","new=oui$dans_rub"), "site-24.gif","creer.gif", false) |
||
| 105 | #. "</div>" |
||
| 106 | ; |
||
| 107 | } |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 111 | $gadget .="</div>"; |
||
| 112 | |||
| 113 | ajax_retour($gadget); |
||
| 114 | } |
||
| 115 | ?> |
||
| 116 |
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.