| Conditions | 6 |
| Paths | 3 |
| Total Lines | 138 |
| 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 | $qb = new QueryBrowser(); |
||
| 20 | |||
| 21 | $query = <<<SQL |
||
| 22 | SELECT |
||
| 23 | COUNT(DISTINCT id) AS 'Requests Closed', |
||
| 24 | YEAR(timestamp) AS 'Year', |
||
| 25 | MONTHNAME(timestamp) AS 'Month' |
||
| 26 | FROM log |
||
| 27 | WHERE action LIKE 'Closed%' |
||
| 28 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 29 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 30 | SQL; |
||
| 31 | |||
| 32 | $out = $qb->executeQueryToTable($query); |
||
| 33 | |||
| 34 | global $showGraphs; |
||
| 35 | if ($showGraphs == 1) { |
||
| 36 | global $filepath; |
||
| 37 | require_once($filepath . 'graph/pChart/pChart.class'); |
||
| 38 | require_once($filepath . 'graph/pChart/pData.class'); |
||
| 39 | |||
| 40 | $queries = array(); |
||
| 41 | |||
| 42 | $queries[] = array( |
||
| 43 | 'query' => <<<SQL |
||
| 44 | SELECT |
||
| 45 | COUNT(DISTINCT id) AS 'y', |
||
| 46 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 47 | FROM log |
||
| 48 | WHERE action LIKE 'Closed%' |
||
| 49 | AND YEAR(timestamp) != 0 |
||
| 50 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 51 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 52 | SQL |
||
| 53 | , |
||
| 54 | 'series' => "All closed requests by month" |
||
| 55 | ); |
||
| 56 | $queries[] = array( |
||
| 57 | 'query' => <<<SQL |
||
| 58 | SELECT |
||
| 59 | COUNT(DISTINCT id) AS 'y', |
||
| 60 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 61 | FROM log |
||
| 62 | WHERE action LIKE 'Closed 0' |
||
| 63 | AND YEAR(timestamp) != 0 |
||
| 64 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 65 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 66 | SQL |
||
| 67 | , |
||
| 68 | 'series' => "Dropped requests by month" |
||
| 69 | ); |
||
| 70 | |||
| 71 | $query = gGetDb()->query("SELECT id, name FROM emailtemplate WHERE active = '1';"); |
||
| 72 | if (!$query) { |
||
| 73 | die("Query error."); |
||
|
|
|||
| 74 | } |
||
| 75 | |||
| 76 | foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) { |
||
| 77 | $id = $row['id']; |
||
| 78 | $name = $row['name']; |
||
| 79 | $queries[] = array( |
||
| 80 | 'query' => <<<SQL |
||
| 81 | SELECT |
||
| 82 | COUNT(DISTINCT id) AS 'y', |
||
| 83 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 84 | FROM log |
||
| 85 | WHERE action LIKE 'Closed $id' |
||
| 86 | AND YEAR(timestamp) != 0 |
||
| 87 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 88 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 89 | SQL |
||
| 90 | , |
||
| 91 | 'series' => "$name requests by month" |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | $queries[] = array( |
||
| 96 | 'query' => <<<SQL |
||
| 97 | SELECT |
||
| 98 | COUNT(DISTINCT id) AS 'y', |
||
| 99 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 100 | FROM log |
||
| 101 | WHERE action = 'Closed custom-y' |
||
| 102 | AND YEAR(timestamp) != 0 |
||
| 103 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 104 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 105 | SQL |
||
| 106 | , |
||
| 107 | 'series' => "Custom created requests by month" |
||
| 108 | ); |
||
| 109 | $queries[] = array( |
||
| 110 | 'query' => <<<SQL |
||
| 111 | SELECT |
||
| 112 | COUNT(DISTINCT id) AS 'y', |
||
| 113 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 114 | FROM log |
||
| 115 | WHERE action = 'Closed custom-n' |
||
| 116 | AND YEAR(timestamp) != 0 |
||
| 117 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 118 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 119 | SQL |
||
| 120 | , |
||
| 121 | 'series' => "Custom not created requests by month" |
||
| 122 | ); |
||
| 123 | |||
| 124 | global $availableRequestStates; |
||
| 125 | foreach ($availableRequestStates as $state) { |
||
| 126 | $queries[] = array( |
||
| 127 | 'query' => <<<SQL |
||
| 128 | SELECT |
||
| 129 | COUNT(DISTINCT id) AS 'y', |
||
| 130 | CONCAT(YEAR(timestamp), '/', MONTHNAME(timestamp)) AS 'x' |
||
| 131 | FROM log |
||
| 132 | WHERE action LIKE 'Deferred to {$state["defertolog"]}' |
||
| 133 | AND YEAR(timestamp) != 0 |
||
| 134 | GROUP BY EXTRACT(YEAR_MONTH FROM timestamp) |
||
| 135 | ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC; |
||
| 136 | SQL |
||
| 137 | , |
||
| 138 | 'series' => "Requests deferred to " . $state['deferto'] . " by month" |
||
| 139 | ); |
||
| 140 | } |
||
| 141 | |||
| 142 | global $baseurl; |
||
| 143 | foreach ($this->createClosuresGraph($queries) as $i) { |
||
| 144 | |||
| 145 | $out .= '<img src="' . $baseurl . '/render/' . $i[0] . '" alt="' . $i[1] . '"/>'; |
||
| 146 | } |
||
| 147 | |||
| 148 | } |
||
| 149 | else { |
||
| 150 | $out .= BootstrapSkin::displayAlertBox("Graph drawing is currently disabled.", "alert-info", "", false, false, true); |
||
| 151 | } |
||
| 152 | |||
| 153 | return $out; |
||
| 154 | } |
||
| 155 | |||
| 245 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.