Conditions | 15 |
Paths | 2754 |
Total Lines | 109 |
Code Lines | 79 |
Lines | 14 |
Ratio | 12.84 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
42 | function lx_Statistics(){ |
||
43 | global $xoopsModule, $xoopsConfig, $xoopsModuleConfig; |
||
44 | xoops_cp_header(); |
||
45 | $myts =& MyTextSanitizer::getInstance(); |
||
46 | |||
47 | // lx_adminMenu(3, _INFO); |
||
48 | |||
49 | $stats = array(); |
||
50 | //$stats=lx_GetStatistics(10); |
||
51 | $stats=lx_GetStatistics($xoopsModuleConfig['perpage']); |
||
52 | $totals=array(0,0,0,0); |
||
53 | |||
54 | // printf("<h1>%s</h1>\n",_AM_LEXIKON_STATS); |
||
55 | $indexAdmin = new ModuleAdmin(); |
||
56 | echo $indexAdmin->addNavigation('statistics.php'); |
||
57 | // First part of the stats, everything about categories |
||
58 | $termspercategory=$stats['termspercategory']; |
||
59 | $readspercategory=$stats['readspercategory']; |
||
60 | $offlinepercategory=$stats['offlinepercategory']; |
||
61 | $authorspercategory=$stats['authorspercategory']; |
||
62 | $class=''; |
||
63 | |||
64 | echo "<div style='text-align: center;'><b>" . _AM_LEXIKON_STATS0 . "</b><br />\n"; |
||
65 | echo "<table width='100%' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' >"; |
||
66 | echo "<tr class='bg3'><td align='center'>"._AM_LEXIKON_ENTRYCATNAME."</td><td align='center'>" . _AM_LEXIKON_TOTALENTRIES . "</td><td>" . _READS . "</td><td>" . _AM_LEXIKON_STATS6 ."</td><td>" ._AM_LEXIKON_STATS1 ."</td></tr>"; |
||
67 | |||
68 | foreach ( $termspercategory as $categoryID => $data ) { |
||
69 | $url=XOOPS_URL . '/modules/' . $xoopsModule -> dirname() . '/category.php?categoryID=' . $categoryID; |
||
70 | $views=0; |
||
71 | if(array_key_exists($categoryID,$readspercategory)) { |
||
72 | $views=$readspercategory[$categoryID]; |
||
73 | } |
||
74 | $offline=0; |
||
75 | if(array_key_exists($categoryID,$offlinepercategory)) { |
||
76 | $offline=$offlinepercategory[$categoryID]; |
||
77 | } |
||
78 | $authors=0; |
||
79 | if(array_key_exists($categoryID,$authorspercategory)) { |
||
80 | $authors=$authorspercategory[$categoryID]; |
||
81 | } |
||
82 | $terms=$data['cpt']; |
||
83 | |||
84 | $totals[0]+=$terms; |
||
85 | $totals[1]+=$views; |
||
86 | $totals[2]+=$offline; |
||
87 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
88 | printf("<tr class='".$class."'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td></tr>\n",$url,$myts->displayTarea($data['name']),$terms,$views,$offline,$authors); |
||
89 | } |
||
90 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
91 | printf("<tr class='".$class."'><td align='center'><b>%s</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td> </td>\n",_AM_LEXIKON_STATS2,$totals[0],$totals[1],$totals[2]); |
||
92 | echo '</table></div><br /><br /><br />'; |
||
93 | |||
94 | // Second part of the stats, everything about reads |
||
95 | // a) Most read definitions |
||
96 | $mostreadterms=$stats['mostreadterms']; |
||
97 | |||
98 | echo "<div style='text-align: center;'><b>" . _AM_LEXIKON_STATS3 . '</b><br /><br />' . _AM_LEXIKON_STATS4 . "<br />\n"; |
||
99 | echo "<table width='100%' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' > |
||
100 | <tr class='bg3'><td align='center'>"._AM_LEXIKON_ENTRYCATNAME."</td><td align='center'>" . _AM_LEXIKON_ENTRYTERM . "</td><td>" . _AM_LEXIKON_AUTHOR . "</td><td>" . _READS . "</td></tr>\n"; |
||
101 | View Code Duplication | foreach ( $mostreadterms as $entryID => $data ) { |
|
102 | $url1=XOOPS_URL . '/modules/' . $xoopsModule -> dirname() . '/category.php?categoryID=' . $data['categoryID']; |
||
103 | $url2=XOOPS_URL . '/modules/' . $xoopsModule -> dirname() . '/entry.php?entryID=' . $entryID; |
||
104 | $sentby = XoopsUserUtility::getUnameFromId($data['uid']); |
||
105 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
106 | printf("<tr class='".$class."'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td>%s</td><td align='right'>%u</td></tr>\n",$url1,$myts->displayTarea($data['name']),$url2,$myts->displayTarea($data['term']),$sentby,$data['counter']); |
||
107 | } |
||
108 | echo '</table>'; |
||
109 | |||
110 | // b) Less read definitions |
||
111 | $lessreadnews=$stats['lessreadterms']; |
||
112 | echo '<br /><br />'._AM_LEXIKON_STATS5; |
||
113 | echo "<table width='100%' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' > |
||
114 | <tr class='bg3'><td align='center'>"._AM_LEXIKON_ENTRYCATNAME."</td><td align='center'>" . _AM_LEXIKON_ENTRYTERM . "</td><td>" . _AM_LEXIKON_AUTHOR . "</td><td>" . _READS . "</td></tr>\n"; |
||
115 | View Code Duplication | foreach ( $lessreadnews as $entryID => $data ) { |
|
116 | $url1=XOOPS_URL . '/modules/' . $xoopsModule -> dirname() . '/category.php?categoryID=' . $data['categoryID']; |
||
117 | $url2=XOOPS_URL . '/modules/' . $xoopsModule -> dirname() . '/entry.php?entryID=' . $entryID; |
||
118 | $sentby = XoopsUserUtility::getUnameFromId($data['uid']); |
||
119 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
120 | printf("<tr class='".$class."'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td>%s</td><td align='right'>%u</td></tr>\n",$url1,$myts->displayTarea($data['name']),$url2,$myts->displayTarea($data['term']),$sentby,$data['counter']); |
||
121 | } |
||
122 | echo '</table>'; |
||
123 | echo '<br /><br /><br />'; |
||
124 | |||
125 | // Last part of the stats, everything about authors |
||
126 | // a) Most read authors |
||
127 | $mostreadauthors=$stats['mostreadauthors']; |
||
128 | echo "<div style='text-align: center;'><b>" . _AM_LEXIKON_STATS10 . '</b><br /><br />' . _AM_LEXIKON_STATS7 . "<br />\n"; |
||
129 | echo "<table width='100%' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' > |
||
130 | <tr class='bg3'><td>"._AM_LEXIKON_AUTHOR.'</td><td>' . _READS . "</td></tr>\n"; |
||
131 | foreach ( $mostreadauthors as $uid => $reads) { |
||
132 | $sentby = XoopsUserUtility::getUnameFromId($uid); |
||
133 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
134 | printf("<tr class='".$class."'><td align='left'>%s</td><td align='right'>%u</td></tr>\n",$sentby,$reads); |
||
135 | } |
||
136 | echo '</table>'; |
||
137 | |||
138 | // c) Biggest contributors |
||
139 | $biggestcontributors=$stats['biggestcontributors']; |
||
140 | echo '<br /><br />'._AM_LEXIKON_STATS9; |
||
141 | echo "<table width='100%' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' > |
||
142 | <tr class='bg3'><td>"._AM_LEXIKON_AUTHOR."</td><td>" . _AM_LEXIKON_STATS11 . "</td></tr>\n"; |
||
143 | foreach ( $biggestcontributors as $uid => $count) { |
||
144 | $url=XOOPS_URL . '/userinfo.php?uid=' . $uid; |
||
145 | $sentby = XoopsUserUtility::getUnameFromId($uid); |
||
146 | $class = ($class == 'even') ? 'odd' : 'even'; |
||
147 | printf("<tr class='".$class."'><td align='left'>%s</td><td align='right'>%u</td></tr>\n",$sentby,$count); |
||
148 | } |
||
149 | echo '</table></div><br />'; |
||
150 | } |
||
151 | |||
162 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.