| Conditions | 1 |
| Paths | 1 |
| Total Lines | 135 |
| 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 |
||
| 17 | protected function execute() |
||
| 18 | { |
||
| 19 | global $smarty; |
||
| 20 | |||
| 21 | $qb = new QueryBrowser(); |
||
| 22 | $qb->numberedList = true; |
||
| 23 | $qb->numberedListTitle = "Position"; |
||
| 24 | |||
| 25 | $qb->tableCallbackFunction = "statsTopCreatorsRowCallback"; |
||
|
|
|||
| 26 | $qb->overrideTableTitles = array("# Created", "Username"); |
||
| 27 | |||
| 28 | // Retrieve all-time stats |
||
| 29 | $top5aout = $qb->executeQueryToTable(<<<SQL |
||
| 30 | SELECT |
||
| 31 | /* StatsTopCreators::execute()/top5aout */ |
||
| 32 | COUNT(*), |
||
| 33 | log.user user_id, |
||
| 34 | user.username log_user, |
||
| 35 | user.status user_level |
||
| 36 | FROM log |
||
| 37 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 38 | INNER JOIN user ON user.id = log.user |
||
| 39 | WHERE emailtemplate.oncreated = '1' |
||
| 40 | OR log.action = 'Closed custom-y' |
||
| 41 | |||
| 42 | GROUP BY log.user, user.username, user.status |
||
| 43 | ORDER BY COUNT(*) DESC; |
||
| 44 | SQL |
||
| 45 | ); |
||
| 46 | |||
| 47 | // Retrieve all-time stats for active users only |
||
| 48 | $top5activeout = $qb->executeQueryToTable(<<<SQL |
||
| 49 | SELECT |
||
| 50 | /* StatsTopCreators::execute()/top5activeout */ |
||
| 51 | COUNT(*), |
||
| 52 | log.user user_id, |
||
| 53 | user.username log_user, |
||
| 54 | user.status user_level |
||
| 55 | FROM log |
||
| 56 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 57 | INNER JOIN user ON user.id = log.user |
||
| 58 | WHERE |
||
| 59 | (emailtemplate.oncreated = 1 OR log.action = 'Closed custom-y') |
||
| 60 | AND user.status != 'Suspended' |
||
| 61 | GROUP BY user.username, user.id |
||
| 62 | ORDER BY COUNT(*) DESC; |
||
| 63 | SQL |
||
| 64 | ); |
||
| 65 | |||
| 66 | // Retrieve today's stats (so far) |
||
| 67 | $now = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"))); |
||
| 68 | $top5out = $qb->executeQueryToTable(<<<SQL |
||
| 69 | SELECT |
||
| 70 | /* StatsTopCreators::execute()/top5out */ |
||
| 71 | COUNT(*), |
||
| 72 | log.user user_id, |
||
| 73 | user.username log_user, |
||
| 74 | user.status user_level |
||
| 75 | FROM log |
||
| 76 | INNER JOIN user ON user.id = log.user |
||
| 77 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
||
| 78 | WHERE (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
||
| 79 | AND log.timestamp LIKE '{$now}%' |
||
| 80 | GROUP BY log.user, user.username |
||
| 81 | ORDER BY COUNT(*) DESC; |
||
| 82 | SQL |
||
| 83 | ); |
||
| 84 | |||
| 85 | // Retrieve Yesterday's stats |
||
| 86 | $yesterday = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1)); |
||
| 87 | $top5yout = $qb->executeQueryToTable(<<<SQL |
||
| 88 | SELECT |
||
| 89 | /* StatsTopCreators::execute()/top5yout */ |
||
| 90 | COUNT(*), |
||
| 91 | log.user user_id, |
||
| 92 | user.username log_user, |
||
| 93 | user.status user_level |
||
| 94 | FROM log |
||
| 95 | INNER JOIN user ON user.id = log.user |
||
| 96 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
||
| 97 | WHERE (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
||
| 98 | AND log.timestamp LIKE '{$yesterday}%' |
||
| 99 | GROUP BY log.user, user.username |
||
| 100 | ORDER BY COUNT(*) DESC; |
||
| 101 | SQL |
||
| 102 | ); |
||
| 103 | |||
| 104 | // Retrieve last 7 days |
||
| 105 | $lastweek = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 7)); |
||
| 106 | $top5wout = $qb->executeQueryToTable(<<<SQL |
||
| 107 | SELECT |
||
| 108 | /* StatsTopCreators::execute()/top5wout */ |
||
| 109 | COUNT(*), |
||
| 110 | log.user user_id, |
||
| 111 | user.username log_user, |
||
| 112 | user.status user_level |
||
| 113 | FROM log |
||
| 114 | INNER JOIN user ON user.id = log.user |
||
| 115 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
||
| 116 | WHERE (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
||
| 117 | AND log.timestamp > '{$lastweek}%' |
||
| 118 | GROUP BY log.user, user.username |
||
| 119 | ORDER BY COUNT(*) DESC; |
||
| 120 | SQL |
||
| 121 | ); |
||
| 122 | |||
| 123 | // Retrieve last month's stats |
||
| 124 | $lastmonth = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 28)); |
||
| 125 | $top5mout = $qb->executeQueryToTable(<<<SQL |
||
| 126 | SELECT |
||
| 127 | /* StatsTopCreators::execute()/top5mout */ |
||
| 128 | COUNT(*), |
||
| 129 | log.user user_id, |
||
| 130 | user.username log_user, |
||
| 131 | user.status user_level |
||
| 132 | FROM log |
||
| 133 | INNER JOIN user ON user.id = log.user |
||
| 134 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
||
| 135 | WHERE (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
||
| 136 | AND log.timestamp > '{$lastmonth}%' |
||
| 137 | GROUP BY log.user, user.username |
||
| 138 | ORDER BY COUNT(*) DESC; |
||
| 139 | SQL |
||
| 140 | ); |
||
| 141 | |||
| 142 | // Put it all together |
||
| 143 | $smarty->assign("top5aout", $top5aout); |
||
| 144 | $smarty->assign("top5activeout", $top5activeout); |
||
| 145 | $smarty->assign("top5out", $top5out); |
||
| 146 | $smarty->assign("top5yout", $top5yout); |
||
| 147 | $smarty->assign("top5wout", $top5wout); |
||
| 148 | $smarty->assign("top5mout", $top5mout); |
||
| 149 | |||
| 150 | return $smarty->fetch("statistics/topcreators.tpl"); |
||
| 151 | } |
||
| 152 | |||
| 202 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..