| Conditions | 25 |
| Paths | > 20000 |
| Total Lines | 143 |
| Code Lines | 91 |
| 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 |
||
| 45 | function exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit,$serveur='') |
||
| 46 | { |
||
| 47 | $titre = $pourarticle = ""; |
||
| 48 | |||
| 49 | if ($id_article){ |
||
| 50 | $row = sql_fetsel("titre, visites, popularite", "spip_articles", "statut='publie' AND id_article=$id_article",'','','','',$serveur); |
||
| 51 | |||
| 52 | if ($row) { |
||
| 53 | $titre = typo($row['titre']); |
||
| 54 | $total_absolu = $row['visites']; |
||
| 55 | $val_popularite = round($row['popularite']); |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | $row = sql_fetsel("SUM(visites) AS total_absolu", "spip_visites",'','','','','',$serveur); |
||
| 59 | $total_absolu = $row ? $row['total_absolu'] : 0; |
||
| 60 | $val_popularite = 0; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($titre) $pourarticle = " "._T('info_pour')." « $titre »"; |
||
| 64 | if ($serveur) { |
||
| 65 | if ($row = sql_fetsel('valeur','spip_meta',"nom='nom_site'",'','','','',$serveur)){ |
||
| 66 | $titre = $row['valeur'].($titre?" / $titre":""); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $commencer_page = charger_fonction('commencer_page', 'inc'); |
||
| 71 | echo $commencer_page(_T('titre_page_statistiques_visites').$pourarticle, "statistiques_visites", "statistiques"); |
||
| 72 | echo gros_titre(_T('titre_evolution_visite')."<html>".aide("confstat")."</html>",'', false); |
||
| 73 | // barre_onglets("statistiques", "evolution"); |
||
| 74 | if ($titre) echo gros_titre($titre,'', false); |
||
| 75 | |||
| 76 | echo debut_gauche('', true); |
||
| 77 | echo "<div class='cadre cadre-e' style='padding: 5px;'>"; |
||
| 78 | echo "<div class='cadre_padding verdana1 spip_x-small'>"; |
||
| 79 | echo typo(_T('info_afficher_visites')); |
||
| 80 | echo "<ul>"; |
||
| 81 | |||
| 82 | if ($id_article>0) { |
||
| 83 | echo "<li><b><a href='" . generer_url_ecrire("statistiques_visites","") . "'>"._T('info_tout_site')."</a></b></li>"; |
||
| 84 | } else { |
||
| 85 | echo "<li><b>"._T('titre_page_articles_tous')."</b></li>"; |
||
| 86 | } |
||
| 87 | |||
| 88 | echo "</ul>"; |
||
| 89 | echo "</div>"; |
||
| 90 | echo "</div>"; |
||
| 91 | |||
| 92 | $classement = array(); |
||
| 93 | $liste = 0; |
||
| 94 | echo aff_statistique_visites_popularite($serveur, $id_article, $classement, $liste); |
||
| 95 | |||
| 96 | // Par visites depuis le debut |
||
| 97 | $result = aff_statistique_visites_par_visites($serveur, $id_article, $classement); |
||
| 98 | |||
| 99 | if ($result OR $id_article) |
||
| 100 | echo creer_colonne_droite('', true); |
||
| 101 | |||
| 102 | if ($id_article) { |
||
| 103 | echo bloc_des_raccourcis(icone_horizontale(_T('icone_retour_article'), generer_url_ecrire("articles","id_article=$id_article"), "article-24.gif","rien.gif", false)); |
||
| 104 | } |
||
| 105 | echo $result; |
||
| 106 | |||
| 107 | echo debut_droite('', true); |
||
| 108 | |||
| 109 | if ($id_article) { |
||
| 110 | $table = "spip_visites_articles"; |
||
| 111 | $table_ref = "spip_referers_articles"; |
||
| 112 | $where = "id_article=$id_article"; |
||
| 113 | |||
| 114 | } else { |
||
| 115 | $table = "spip_visites"; |
||
| 116 | $table_ref = "spip_referers"; |
||
| 117 | $where = ""; |
||
| 118 | } |
||
| 119 | |||
| 120 | $order = "date"; |
||
| 121 | |||
| 122 | $where2 = $duree ? "$order > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL $duree $type)": ''; |
||
| 123 | if ($where) $where2 = $where2 ? "$where2 AND $where" : $where; |
||
| 124 | |||
| 125 | // sur certains SQL, la division produit un entier tronque a la valeur inferieure |
||
| 126 | // on ne peut donc faire un CEIL, il faut faire un FLOOR |
||
| 127 | $log = statistiques_collecte_date('visites', "(FLOOR((UNIX_TIMESTAMP($order)+$interval-1) / $interval) * $interval)", $table, $where2, $serveur); |
||
| 128 | |||
| 129 | if ($log) |
||
|
|
|||
| 130 | $res = statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total_absolu, $val_popularite, $classement, $liste); |
||
| 131 | |||
| 132 | $mois = statistiques_collecte_date("SUM(visites)", |
||
| 133 | "DATE_FORMAT($order,'%Y%m')", |
||
| 134 | $table, |
||
| 135 | "$order > DATE_SUB(NOW(),INTERVAL 2700 DAY)" |
||
| 136 | . ($where ? " AND $where" : ''), |
||
| 137 | $serveur); |
||
| 138 | |||
| 139 | if (count($mois)>1) { |
||
| 140 | $res[] = "<br /><span class='verdana1 spip_small'><b>" |
||
| 141 | . _T('info_visites_par_mois') |
||
| 142 | . "</b></span>" |
||
| 143 | . statistiques_par_mois($mois, ''); |
||
| 144 | } |
||
| 145 | echo cadre_stat($res, $table, $id_article); |
||
| 146 | |||
| 147 | if ($id_article) { |
||
| 148 | $signatures = charger_fonction('signatures', 'statistiques'); |
||
| 149 | echo $signatures($duree, $interval, $type, $id_article, $serveur); |
||
| 150 | /* |
||
| 151 | Il faudra optimiser les requetes de ces stats c'est vraiment trop horrible : |
||
| 152 | plusieurs secondes d'attente sur un site comme contrib. |
||
| 153 | par ailleurs, l'affichage presente des defauts : |
||
| 154 | cf http://trac.rezo.net/trac/spip/ticket/1598 |
||
| 155 | $forums = charger_fonction('forums', 'statistiques'); |
||
| 156 | echo $forums($duree, $interval, $type, $id_article, $serveur); |
||
| 157 | */ |
||
| 158 | } |
||
| 159 | |||
| 160 | |||
| 161 | $referenceurs = charger_fonction('referenceurs', 'inc'); |
||
| 162 | $res = $referenceurs($id_article, "visites", $table_ref, $where, '', $limit); |
||
| 163 | |||
| 164 | if ($res) { |
||
| 165 | |||
| 166 | // Le lien pour en afficher "plus" |
||
| 167 | $args = ($id_article?"id_article=$id_article&" : '') . "limit=" . strval($limit+200); |
||
| 168 | $n = count($res); |
||
| 169 | $plus = generer_url_ecrire('statistiques_visites', $args); |
||
| 170 | if ($plus) { |
||
| 171 | $plus = "<div style='text-align:right;'><b><a href='$plus'>+++</a></b></div>"; |
||
| 172 | } |
||
| 173 | $titre = _T("onglet_origine_visites") |
||
| 174 | . " ($n " |
||
| 175 | . ($n == 1 ? _T('info_site') : _T('info_sites')) |
||
| 176 | . ")"; |
||
| 177 | echo '<br />', gros_titre($titre,'', false); |
||
| 178 | echo "<div style='overflow:hidden;' class='verdana1 spip_small'><br />"; |
||
| 179 | echo "<ul class='referers'><li>"; |
||
| 180 | echo join("</li><li>\n",$res); |
||
| 181 | echo "</li></ul>"; |
||
| 182 | echo $plus; |
||
| 183 | echo "<br /></div>"; |
||
| 184 | } |
||
| 185 | |||
| 186 | echo fin_gauche(), fin_page(); |
||
| 187 | } |
||
| 188 | ?> |
||
| 189 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.