@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | Console::log('Ending log below with a sample error.'); |
50 | 50 | throw new Exception('Unable to write to log!'); |
51 | 51 | } |
52 | - catch(Exception $e) { |
|
52 | + catch (Exception $e) { |
|
53 | 53 | Console::logError($e, 'Sample error logging.'); |
54 | 54 | } |
55 | 55 | } |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | $ret = ''; |
85 | 85 | $longString = 'This is a really long string that when appended with the . symbol |
86 | 86 | will cause memory to be duplicated in order to create the new string.'; |
87 | - for($i = 0; $i < 10; $i++) { |
|
88 | - $ret = $ret . $longString; |
|
87 | + for ($i = 0; $i < 10; $i++) { |
|
88 | + $ret = $ret.$longString; |
|
89 | 89 | Console::logMemory($ret, 'Watch memory leak -- iteration '.$i); |
90 | 90 | } |
91 | 91 | } |
@@ -48,8 +48,7 @@ |
||
48 | 48 | Console::logMemory($this, 'PQP Example Class : Line '.__LINE__); |
49 | 49 | Console::log('Ending log below with a sample error.'); |
50 | 50 | throw new Exception('Unable to write to log!'); |
51 | - } |
|
52 | - catch(Exception $e) { |
|
51 | + } catch(Exception $e) { |
|
53 | 52 | Console::logError($e, 'Sample error logging.'); |
54 | 53 | } |
55 | 54 | } |
@@ -167,8 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | if($logCount == 0) { |
169 | 169 | echo '<h3>This panel has no log items.</h3>'; |
170 | -} |
|
171 | -else { |
|
170 | +} else { |
|
172 | 171 | echo '<table class="side" cellspacing="0"> |
173 | 172 | <tr> |
174 | 173 | <td class="alt1"><var>'.$output['logs']['logCount'].'</var><h4>Logs</h4></td> |
@@ -188,20 +187,20 @@ discard block |
||
188 | 187 | <td class="'.$class.'">'; |
189 | 188 | if($log['type'] == 'log') { |
190 | 189 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
191 | - } |
|
192 | - elseif($log['type'] == 'memory') { |
|
190 | + } elseif($log['type'] == 'memory') { |
|
193 | 191 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['dataType'].'</em>: '.$log['name'].' </div>'; |
194 | - } |
|
195 | - elseif($log['type'] == 'speed') { |
|
192 | + } elseif($log['type'] == 'speed') { |
|
196 | 193 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
197 | - } |
|
198 | - elseif($log['type'] == 'error') { |
|
194 | + } elseif($log['type'] == 'error') { |
|
199 | 195 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
200 | 196 | } |
201 | 197 | |
202 | 198 | echo '</td></tr>'; |
203 | - if($class == '') $class = 'alt'; |
|
204 | - else $class = ''; |
|
199 | + if($class == '') { |
|
200 | + $class = 'alt'; |
|
201 | + } else { |
|
202 | + $class = ''; |
|
203 | + } |
|
205 | 204 | } |
206 | 205 | |
207 | 206 | echo '</table>'; |
@@ -213,8 +212,7 @@ discard block |
||
213 | 212 | |
214 | 213 | if($output['logs']['speedCount'] == 0) { |
215 | 214 | echo '<h3>This panel has no log items.</h3>'; |
216 | -} |
|
217 | -else { |
|
215 | +} else { |
|
218 | 216 | echo '<table class="side" cellspacing="0"> |
219 | 217 | <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr> |
220 | 218 | <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr> |
@@ -228,8 +226,11 @@ discard block |
||
228 | 226 | <td class="'.$class.'">'; |
229 | 227 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
230 | 228 | echo '</td></tr>'; |
231 | - if($class == '') $class = 'alt'; |
|
232 | - else $class = ''; |
|
229 | + if($class == '') { |
|
230 | + $class = 'alt'; |
|
231 | + } else { |
|
232 | + $class = ''; |
|
233 | + } |
|
233 | 234 | } |
234 | 235 | } |
235 | 236 | |
@@ -242,8 +243,7 @@ discard block |
||
242 | 243 | |
243 | 244 | if($output['queryTotals']['count'] == 0) { |
244 | 245 | echo '<h3>This panel has no log items.</h3>'; |
245 | -} |
|
246 | -else { |
|
246 | +} else { |
|
247 | 247 | echo '<table class="side" cellspacing="0"> |
248 | 248 | <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr> |
249 | 249 | <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr> |
@@ -265,8 +265,11 @@ discard block |
||
265 | 265 | </em>'; |
266 | 266 | } |
267 | 267 | echo '</td></tr>'; |
268 | - if($class == '') $class = 'alt'; |
|
269 | - else $class = ''; |
|
268 | + if($class == '') { |
|
269 | + $class = 'alt'; |
|
270 | + } else { |
|
271 | + $class = ''; |
|
272 | + } |
|
270 | 273 | } |
271 | 274 | |
272 | 275 | echo '</table>'; |
@@ -278,8 +281,7 @@ discard block |
||
278 | 281 | |
279 | 282 | if($output['logs']['memoryCount'] == 0) { |
280 | 283 | echo '<h3>This panel has no log items.</h3>'; |
281 | -} |
|
282 | -else { |
|
284 | +} else { |
|
283 | 285 | echo '<table class="side" cellspacing="0"> |
284 | 286 | <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr> |
285 | 287 | <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr> |
@@ -292,8 +294,11 @@ discard block |
||
292 | 294 | echo '<tr class="log-'.$log['type'].'">'; |
293 | 295 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>'; |
294 | 296 | echo '</tr>'; |
295 | - if($class == '') $class = 'alt'; |
|
296 | - else $class = ''; |
|
297 | + if($class == '') { |
|
298 | + $class = 'alt'; |
|
299 | + } else { |
|
300 | + $class = ''; |
|
301 | + } |
|
297 | 302 | } |
298 | 303 | } |
299 | 304 | |
@@ -306,8 +311,7 @@ discard block |
||
306 | 311 | |
307 | 312 | if($output['fileTotals']['count'] == 0) { |
308 | 313 | echo '<h3>This panel has no log items.</h3>'; |
309 | -} |
|
310 | -else { |
|
314 | +} else { |
|
311 | 315 | echo '<table class="side" cellspacing="0"> |
312 | 316 | <tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr> |
313 | 317 | <tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr> |
@@ -318,8 +322,11 @@ discard block |
||
318 | 322 | $class =''; |
319 | 323 | foreach($output['files'] as $file) { |
320 | 324 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
321 | - if($class == '') $class = 'alt'; |
|
322 | - else $class = ''; |
|
325 | + if($class == '') { |
|
326 | + $class = 'alt'; |
|
327 | + } else { |
|
328 | + $class = ''; |
|
329 | + } |
|
323 | 330 | } |
324 | 331 | |
325 | 332 | echo '</table>'; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | function displayPqp($output, $config) { |
19 | 19 | |
20 | -$css = file_get_contents(__DIR__ . '/css/pQp.css'); |
|
20 | +$css = file_get_contents(__DIR__.'/css/pQp.css'); |
|
21 | 21 | |
22 | 22 | echo <<<JAVASCRIPT |
23 | 23 | <!-- JavaScript --> |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | echo '<div id="pqp-console" class="pqp-box">'; |
163 | 163 | |
164 | -if($logCount == 0) { |
|
164 | +if ($logCount == 0) { |
|
165 | 165 | echo '<h3>This panel has no log items.</h3>'; |
166 | 166 | } |
167 | 167 | else { |
@@ -179,25 +179,25 @@ discard block |
||
179 | 179 | <table class="main" cellspacing="0">'; |
180 | 180 | |
181 | 181 | $class = ''; |
182 | - foreach($output['logs']['console']['messages'] as $log) { |
|
182 | + foreach ($output['logs']['console']['messages'] as $log) { |
|
183 | 183 | echo '<tr class="log-'.$log['type'].'"> |
184 | 184 | <td class="type">'.$log['type'].'</td> |
185 | 185 | <td class="'.$class.'">'; |
186 | - if($log['type'] == 'log') { |
|
186 | + if ($log['type'] == 'log') { |
|
187 | 187 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
188 | 188 | } |
189 | - elseif($log['type'] == 'memory') { |
|
189 | + elseif ($log['type'] == 'memory') { |
|
190 | 190 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['data_type'].'</em>: '.$log['name'].' </div>'; |
191 | 191 | } |
192 | - elseif($log['type'] == 'speed') { |
|
192 | + elseif ($log['type'] == 'speed') { |
|
193 | 193 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
194 | 194 | } |
195 | - elseif($log['type'] == 'error') { |
|
195 | + elseif ($log['type'] == 'error') { |
|
196 | 196 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
197 | 197 | } |
198 | 198 | |
199 | 199 | echo '</td></tr>'; |
200 | - if($class == '') $class = 'alt'; |
|
200 | + if ($class == '') $class = 'alt'; |
|
201 | 201 | else $class = ''; |
202 | 202 | } |
203 | 203 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | |
209 | 209 | echo '<div id="pqp-speed" class="pqp-box">'; |
210 | 210 | |
211 | -if($output['logs']['speedCount'] == 0) { |
|
211 | +if ($output['logs']['speedCount'] == 0) { |
|
212 | 212 | echo '<h3>This panel has no log items.</h3>'; |
213 | 213 | } |
214 | 214 | else { |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | <table class="main" cellspacing="0">'; |
220 | 220 | |
221 | 221 | $class = ''; |
222 | - foreach($output['logs']['console'] as $log) { |
|
223 | - if($log['type'] == 'speed') { |
|
222 | + foreach ($output['logs']['console'] as $log) { |
|
223 | + if ($log['type'] == 'speed') { |
|
224 | 224 | echo '<tr class="log-'.$log['type'].'"> |
225 | 225 | <td class="'.$class.'">'; |
226 | 226 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
227 | 227 | echo '</td></tr>'; |
228 | - if($class == '') $class = 'alt'; |
|
228 | + if ($class == '') $class = 'alt'; |
|
229 | 229 | else $class = ''; |
230 | 230 | } |
231 | 231 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | echo '<div id="pqp-queries" class="pqp-box">'; |
239 | 239 | |
240 | -if($output['queryTotals']['count'] == 0) { |
|
240 | +if ($output['queryTotals']['count'] == 0) { |
|
241 | 241 | echo '<h3>This panel has no log items.</h3>'; |
242 | 242 | } |
243 | 243 | else { |
@@ -249,10 +249,10 @@ discard block |
||
249 | 249 | <table class="main" cellspacing="0">'; |
250 | 250 | |
251 | 251 | $class = ''; |
252 | - foreach($output['queries'] as $query) { |
|
252 | + foreach ($output['queries'] as $query) { |
|
253 | 253 | echo '<tr> |
254 | 254 | <td class="'.$class.'">'.$query['sql']; |
255 | - if($query['explain']) { |
|
255 | + if ($query['explain']) { |
|
256 | 256 | echo '<em> |
257 | 257 | Possible keys: <b>'.$query['explain']['possible_keys'].'</b> · |
258 | 258 | Key Used: <b>'.$query['explain']['key'].'</b> · |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | </em>'; |
263 | 263 | } |
264 | 264 | echo '</td></tr>'; |
265 | - if($class == '') $class = 'alt'; |
|
265 | + if ($class == '') $class = 'alt'; |
|
266 | 266 | else $class = ''; |
267 | 267 | } |
268 | 268 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | |
274 | 274 | echo '<div id="pqp-memory" class="pqp-box">'; |
275 | 275 | |
276 | -if($output['logs']['memoryCount'] == 0) { |
|
276 | +if ($output['logs']['memoryCount'] == 0) { |
|
277 | 277 | echo '<h3>This panel has no log items.</h3>'; |
278 | 278 | } |
279 | 279 | else { |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | <table class="main" cellspacing="0">'; |
285 | 285 | |
286 | 286 | $class = ''; |
287 | - foreach($output['logs']['console'] as $log) { |
|
288 | - if($log['type'] == 'memory') { |
|
287 | + foreach ($output['logs']['console'] as $log) { |
|
288 | + if ($log['type'] == 'memory') { |
|
289 | 289 | echo '<tr class="log-'.$log['type'].'">'; |
290 | 290 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>'; |
291 | 291 | echo '</tr>'; |
292 | - if($class == '') $class = 'alt'; |
|
292 | + if ($class == '') $class = 'alt'; |
|
293 | 293 | else $class = ''; |
294 | 294 | } |
295 | 295 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | echo '<div id="pqp-files" class="pqp-box">'; |
303 | 303 | |
304 | -if($output['fileTotals']['count'] == 0) { |
|
304 | +if ($output['fileTotals']['count'] == 0) { |
|
305 | 305 | echo '<h3>This panel has no log items.</h3>'; |
306 | 306 | } |
307 | 307 | else { |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | </table> |
313 | 313 | <table class="main" cellspacing="0">'; |
314 | 314 | |
315 | - $class =''; |
|
316 | - foreach($output['files'] as $file) { |
|
315 | + $class = ''; |
|
316 | + foreach ($output['files'] as $file) { |
|
317 | 317 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
318 | - if($class == '') $class = 'alt'; |
|
318 | + if ($class == '') $class = 'alt'; |
|
319 | 319 | else $class = ''; |
320 | 320 | } |
321 | 321 |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | |
38 | 38 | function connect($new = false) { |
39 | 39 | $this->conn = mysql_connect($this->host, $this->user, $this->password, $new); |
40 | - if(!$this->conn) { |
|
40 | + if (!$this->conn) { |
|
41 | 41 | throw new Exception('We\'re working on a few connection issues.'); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | function changeDatabase($database) { |
46 | 46 | $this->database = $database; |
47 | - if($this->conn) { |
|
48 | - if(!mysql_select_db($database, $this->conn)) { |
|
47 | + if ($this->conn) { |
|
48 | + if (!mysql_select_db($database, $this->conn)) { |
|
49 | 49 | throw new CustomException('We\'re working on a few connection issues.'); |
50 | 50 | } |
51 | 51 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | function lazyLoadConnection() { |
55 | 55 | $this->connect(true); |
56 | - if($this->database) $this->changeDatabase($this->database); |
|
56 | + if ($this->database) $this->changeDatabase($this->database); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /*----------------------------------- |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | ------------------------------------*/ |
62 | 62 | |
63 | 63 | function query($sql) { |
64 | - if(!$this->conn) $this->lazyLoadConnection(); |
|
64 | + if (!$this->conn) $this->lazyLoadConnection(); |
|
65 | 65 | $start = $this->getTime(); |
66 | 66 | $rs = mysql_query($sql, $this->conn); |
67 | 67 | $this->queryCount += 1; |
68 | 68 | $this->logQuery($sql, $start); |
69 | - if(!$rs) { |
|
69 | + if (!$rs) { |
|
70 | 70 | throw new Exception('Could not execute query.'); |
71 | 71 | } |
72 | 72 | return $rs; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | function logQuery($sql, $start) { |
80 | 80 | $query = array( |
81 | 81 | 'sql' => $sql, |
82 | - 'time' => ($this->getTime() - $start)*1000 |
|
82 | + 'time' => ($this->getTime() - $start) * 1000 |
|
83 | 83 | ); |
84 | 84 | array_push($this->queries, $query); |
85 | 85 | } |
@@ -96,19 +96,19 @@ discard block |
||
96 | 96 | $ret = $time; |
97 | 97 | $formatter = 0; |
98 | 98 | $formats = array('ms', 's', 'm'); |
99 | - if($time >= 1000 && $time < 60000) { |
|
99 | + if ($time >= 1000 && $time < 60000) { |
|
100 | 100 | $formatter = 1; |
101 | 101 | $ret = ($time / 1000); |
102 | 102 | } |
103 | - if($time >= 60000) { |
|
103 | + if ($time >= 60000) { |
|
104 | 104 | $formatter = 2; |
105 | 105 | $ret = ($time / 1000) / 60; |
106 | 106 | } |
107 | - $ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter]; |
|
107 | + $ret = number_format($ret, 3, '.', '').' '.$formats[$formatter]; |
|
108 | 108 | return $ret; |
109 | 109 | } |
110 | 110 | |
111 | - function __destruct() { |
|
111 | + function __destruct() { |
|
112 | 112 | @mysql_close($this->conn); |
113 | 113 | } |
114 | 114 |
@@ -53,7 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | function lazyLoadConnection() { |
55 | 55 | $this->connect(true); |
56 | - if($this->database) $this->changeDatabase($this->database); |
|
56 | + if($this->database) { |
|
57 | + $this->changeDatabase($this->database); |
|
58 | + } |
|
57 | 59 | } |
58 | 60 | |
59 | 61 | /*----------------------------------- |
@@ -61,7 +63,9 @@ discard block |
||
61 | 63 | ------------------------------------*/ |
62 | 64 | |
63 | 65 | function query($sql) { |
64 | - if(!$this->conn) $this->lazyLoadConnection(); |
|
66 | + if(!$this->conn) { |
|
67 | + $this->lazyLoadConnection(); |
|
68 | + } |
|
65 | 69 | $start = $this->getTime(); |
66 | 70 | $rs = mysql_query($sql, $this->conn); |
67 | 71 | $this->queryCount += 1; |
@@ -37,11 +37,9 @@ discard block |
||
37 | 37 | foreach($logs['console'] as $key => $log) { |
38 | 38 | if($log['type'] == 'log') { |
39 | 39 | $logs['console'][$key]['data'] = print_r($log['data'], true); |
40 | - } |
|
41 | - elseif($log['type'] == 'memory') { |
|
40 | + } elseif($log['type'] == 'memory') { |
|
42 | 41 | $logs['console'][$key]['data'] = $this->getReadableFileSize($log['data']); |
43 | - } |
|
44 | - elseif($log['type'] == 'speed') { |
|
42 | + } elseif($log['type'] == 'speed') { |
|
45 | 43 | $logs['console'][$key]['data'] = $this->getReadableTime(($log['data'] - $this->startTime)*1000); |
46 | 44 | } |
47 | 45 | } |
@@ -69,7 +67,9 @@ discard block |
||
69 | 67 | 'size' => $this->getReadableFileSize($size) |
70 | 68 | ); |
71 | 69 | $fileTotals['size'] += $size; |
72 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
70 | + if($size > $fileTotals['largest']) { |
|
71 | + $fileTotals['largest'] = $size; |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
@@ -122,8 +122,7 @@ discard block |
||
122 | 122 | try { |
123 | 123 | $sql = 'EXPLAIN '.$query['sql']; |
124 | 124 | $rs = $this->db->query($sql); |
125 | - } |
|
126 | - catch(Exception $e) {} |
|
125 | + } catch(Exception $e) {} |
|
127 | 126 | if($rs) { |
128 | 127 | $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
129 | 128 | $query['explain'] = $row; |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | protected $console; |
25 | 25 | |
26 | 26 | public function __construct($console, $startTime = null) { |
27 | - $this->console = $console; |
|
27 | + $this->console = $console; |
|
28 | 28 | |
29 | - if (is_null($startTime)) { |
|
30 | - $startTime = microtime(true); |
|
31 | - } |
|
29 | + if (is_null($startTime)) { |
|
30 | + $startTime = microtime(true); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | $this->startTime = $startTime; |
34 | 34 | } |
@@ -38,49 +38,49 @@ discard block |
||
38 | 38 | -------------------------------------------*/ |
39 | 39 | |
40 | 40 | public function gatherConsoleData() { |
41 | - $console = array( |
|
42 | - 'messages' => array(), |
|
43 | - 'totals' => array( |
|
44 | - 'log' => 0, |
|
45 | - 'memory' => 0, |
|
46 | - 'error' => 0, |
|
47 | - 'speed' => 0 |
|
48 | - )); |
|
41 | + $console = array( |
|
42 | + 'messages' => array(), |
|
43 | + 'totals' => array( |
|
44 | + 'log' => 0, |
|
45 | + 'memory' => 0, |
|
46 | + 'error' => 0, |
|
47 | + 'speed' => 0 |
|
48 | + )); |
|
49 | 49 | $logs = $this->console->getLogs(); |
50 | 50 | foreach($logs as $log) { |
51 | 51 | if($log['type'] == 'log') { |
52 | 52 | $message = array( |
53 | - 'data' => print_r($log['data'], true), |
|
54 | - 'type' => 'log' |
|
55 | - ); |
|
56 | - $console['totals']['log']++; |
|
53 | + 'data' => print_r($log['data'], true), |
|
54 | + 'type' => 'log' |
|
55 | + ); |
|
56 | + $console['totals']['log']++; |
|
57 | 57 | } |
58 | 58 | elseif($log['type'] == 'memory') { |
59 | 59 | $message = array( |
60 | - 'name' => $log['name'], |
|
61 | - 'data_type' => $log['data_type'], |
|
62 | - 'data' => $this->getReadableFileSize($log['data']), |
|
63 | - 'type' => 'memory' |
|
64 | - ); |
|
65 | - $console['totals']['memory']++; |
|
60 | + 'name' => $log['name'], |
|
61 | + 'data_type' => $log['data_type'], |
|
62 | + 'data' => $this->getReadableFileSize($log['data']), |
|
63 | + 'type' => 'memory' |
|
64 | + ); |
|
65 | + $console['totals']['memory']++; |
|
66 | 66 | } |
67 | 67 | elseif($log['type'] == 'speed') { |
68 | - $message = array( |
|
69 | - 'name' => $log['name'], |
|
70 | - 'data' => $this->getReadableTime(($log['data'] - $this->startTime) * 1000), |
|
71 | - 'type' => 'speed' |
|
72 | - ); |
|
73 | - $console['totals']['speed']++; |
|
68 | + $message = array( |
|
69 | + 'name' => $log['name'], |
|
70 | + 'data' => $this->getReadableTime(($log['data'] - $this->startTime) * 1000), |
|
71 | + 'type' => 'speed' |
|
72 | + ); |
|
73 | + $console['totals']['speed']++; |
|
74 | 74 | } else { |
75 | - $message = array( |
|
76 | - 'data' => $log['data'], |
|
77 | - 'type' => 'error', |
|
78 | - 'file' => $log['file'], |
|
79 | - 'line' => $log['line'] |
|
80 | - ); |
|
81 | - $console['totals']['error']++; |
|
82 | - } |
|
83 | - array_push($console['messages'], $message); |
|
75 | + $message = array( |
|
76 | + 'data' => $log['data'], |
|
77 | + 'type' => 'error', |
|
78 | + 'file' => $log['file'], |
|
79 | + 'line' => $log['line'] |
|
80 | + ); |
|
81 | + $console['totals']['error']++; |
|
82 | + } |
|
83 | + array_push($console['messages'], $message); |
|
84 | 84 | } |
85 | 85 | $this->output['logs'] = array('console' => $console); |
86 | 86 | } |
@@ -183,19 +183,19 @@ discard block |
||
183 | 183 | -------------------------------------------*/ |
184 | 184 | |
185 | 185 | public function getReadableFileSize($size, $retstring = null) { |
186 | - // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
187 | - $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
186 | + // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
187 | + $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
188 | 188 | |
189 | - if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
189 | + if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
190 | 190 | |
191 | 191 | $lastsizestring = end($sizes); |
192 | 192 | |
193 | 193 | foreach ($sizes as $sizestring) { |
194 | - if ($size < 1024) { break; } |
|
195 | - if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
196 | - } |
|
197 | - if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
198 | - return sprintf($retstring, $size, $sizestring); |
|
194 | + if ($size < 1024) { break; } |
|
195 | + if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
196 | + } |
|
197 | + if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
198 | + return sprintf($retstring, $size, $sizestring); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | public function getReadableTime($time) { |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | 'speed' => 0 |
48 | 48 | )); |
49 | 49 | $logs = $this->console->getLogs(); |
50 | - foreach($logs as $log) { |
|
51 | - if($log['type'] == 'log') { |
|
50 | + foreach ($logs as $log) { |
|
51 | + if ($log['type'] == 'log') { |
|
52 | 52 | $message = array( |
53 | 53 | 'data' => print_r($log['data'], true), |
54 | 54 | 'type' => 'log' |
55 | 55 | ); |
56 | 56 | $console['totals']['log']++; |
57 | 57 | } |
58 | - elseif($log['type'] == 'memory') { |
|
58 | + elseif ($log['type'] == 'memory') { |
|
59 | 59 | $message = array( |
60 | 60 | 'name' => $log['name'], |
61 | 61 | 'data_type' => $log['data_type'], |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | ); |
65 | 65 | $console['totals']['memory']++; |
66 | 66 | } |
67 | - elseif($log['type'] == 'speed') { |
|
67 | + elseif ($log['type'] == 'speed') { |
|
68 | 68 | $message = array( |
69 | 69 | 'name' => $log['name'], |
70 | 70 | 'data' => $this->getReadableTime(($log['data'] - $this->startTime) * 1000), |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | "largest" => 0, |
99 | 99 | ); |
100 | 100 | |
101 | - foreach($files as $key => $file) { |
|
101 | + foreach ($files as $key => $file) { |
|
102 | 102 | $size = filesize($file); |
103 | 103 | $fileList[] = array( |
104 | 104 | 'name' => $file, |
105 | 105 | 'size' => $this->getReadableFileSize($size) |
106 | 106 | ); |
107 | 107 | $fileTotals['size'] += $size; |
108 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
108 | + if ($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | $queryTotals['time'] = 0; |
136 | 136 | $queries = array(); |
137 | 137 | |
138 | - if($this->db != '') { |
|
138 | + if ($this->db != '') { |
|
139 | 139 | $queryTotals['count'] += $this->db->queryCount; |
140 | - foreach($this->db->queries as $key => $query) { |
|
140 | + foreach ($this->db->queries as $key => $query) { |
|
141 | 141 | $query = $this->attemptToExplainQuery($query); |
142 | 142 | $queryTotals['time'] += $query['time']; |
143 | 143 | $query['time'] = $this->getReadableTime($query['time']); |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | $sql = 'EXPLAIN '.$query['sql']; |
160 | 160 | $rs = $this->db->query($sql); |
161 | 161 | } |
162 | - catch(Exception $e) {} |
|
163 | - if($rs) { |
|
162 | + catch (Exception $e) {} |
|
163 | + if ($rs) { |
|
164 | 164 | $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
165 | 165 | $query['explain'] = $row; |
166 | 166 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | public function gatherSpeedData() { |
175 | 175 | $speedTotals = array(); |
176 | - $speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime)*1000); |
|
176 | + $speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime) * 1000); |
|
177 | 177 | $speedTotals['allowed'] = ini_get("max_execution_time"); |
178 | 178 | $this->output['speedTotals'] = $speedTotals; |
179 | 179 | } |
@@ -202,15 +202,15 @@ discard block |
||
202 | 202 | $ret = $time; |
203 | 203 | $formatter = 0; |
204 | 204 | $formats = array('ms', 's', 'm'); |
205 | - if($time >= 1000 && $time < 60000) { |
|
205 | + if ($time >= 1000 && $time < 60000) { |
|
206 | 206 | $formatter = 1; |
207 | 207 | $ret = ($time / 1000); |
208 | 208 | } |
209 | - if($time >= 60000) { |
|
209 | + if ($time >= 60000) { |
|
210 | 210 | $formatter = 2; |
211 | 211 | $ret = ($time / 1000) / 60; |
212 | 212 | } |
213 | - $ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter]; |
|
213 | + $ret = number_format($ret, 3, '.', '').' '.$formats[$formatter]; |
|
214 | 214 | return $ret; |
215 | 215 | } |
216 | 216 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $this->gatherMemoryData(); |
227 | 227 | $this->gatherQueryData(); |
228 | 228 | $this->gatherSpeedData(); |
229 | - require_once __DIR__ . '/../display.php'; |
|
229 | + require_once __DIR__.'/../display.php'; |
|
230 | 230 | displayPqp($this->output); |
231 | 231 | } |
232 | 232 |
@@ -15,86 +15,86 @@ |
||
15 | 15 | class Console |
16 | 16 | { |
17 | 17 | |
18 | - /** @var array */ |
|
19 | - protected $store = array(); |
|
18 | + /** @var array */ |
|
19 | + protected $store = array(); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Logs data to the console |
|
23 | - * Accepts any data type |
|
24 | - * |
|
25 | - * @param mixed $data |
|
26 | - */ |
|
27 | - public function log($data) |
|
28 | - { |
|
29 | - array_push($this->store, array( |
|
30 | - 'data' => $data, |
|
31 | - 'type' => 'log' |
|
32 | - )); |
|
33 | - } |
|
21 | + /** |
|
22 | + * Logs data to the console |
|
23 | + * Accepts any data type |
|
24 | + * |
|
25 | + * @param mixed $data |
|
26 | + */ |
|
27 | + public function log($data) |
|
28 | + { |
|
29 | + array_push($this->store, array( |
|
30 | + 'data' => $data, |
|
31 | + 'type' => 'log' |
|
32 | + )); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Logs memory usage of a variable |
|
37 | - * If no parameter is passed in, logs current memory usage |
|
38 | - * |
|
39 | - * @param mixed $object |
|
40 | - * @param string $name |
|
41 | - */ |
|
42 | - public function logMemory($object = null, $name = '') |
|
43 | - { |
|
44 | - $memory = memory_get_usage(); |
|
45 | - if (!is_null($object)) { |
|
46 | - $memory = strlen(serialize($object)); |
|
47 | - } |
|
35 | + /** |
|
36 | + * Logs memory usage of a variable |
|
37 | + * If no parameter is passed in, logs current memory usage |
|
38 | + * |
|
39 | + * @param mixed $object |
|
40 | + * @param string $name |
|
41 | + */ |
|
42 | + public function logMemory($object = null, $name = '') |
|
43 | + { |
|
44 | + $memory = memory_get_usage(); |
|
45 | + if (!is_null($object)) { |
|
46 | + $memory = strlen(serialize($object)); |
|
47 | + } |
|
48 | 48 | |
49 | - array_push($this->store, array( |
|
50 | - 'name' => $name, |
|
51 | - 'data' => $memory, |
|
52 | - 'data_type' => gettype($object), |
|
53 | - 'type' => 'memory' |
|
54 | - )); |
|
55 | - } |
|
49 | + array_push($this->store, array( |
|
50 | + 'name' => $name, |
|
51 | + 'data' => $memory, |
|
52 | + 'data_type' => gettype($object), |
|
53 | + 'type' => 'memory' |
|
54 | + )); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Logs exception with optional message override |
|
59 | - * |
|
60 | - * @param Exception $exception |
|
61 | - * @param string $message |
|
62 | - */ |
|
63 | - public function logError(Exception $exception, $message = '') |
|
64 | - { |
|
65 | - if (empty($message)) { |
|
66 | - $message = $exception->getMessage(); |
|
67 | - } |
|
57 | + /** |
|
58 | + * Logs exception with optional message override |
|
59 | + * |
|
60 | + * @param Exception $exception |
|
61 | + * @param string $message |
|
62 | + */ |
|
63 | + public function logError(Exception $exception, $message = '') |
|
64 | + { |
|
65 | + if (empty($message)) { |
|
66 | + $message = $exception->getMessage(); |
|
67 | + } |
|
68 | 68 | |
69 | - array_push($this->store, array( |
|
70 | - 'data' => $message, |
|
71 | - 'file' => $exception->getFile(), |
|
72 | - 'line' => $exception->getLine(), |
|
73 | - 'type' => 'error' |
|
74 | - )); |
|
75 | - } |
|
69 | + array_push($this->store, array( |
|
70 | + 'data' => $message, |
|
71 | + 'file' => $exception->getFile(), |
|
72 | + 'line' => $exception->getLine(), |
|
73 | + 'type' => 'error' |
|
74 | + )); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Logs current time with optional message |
|
79 | - * |
|
80 | - * @param string $name |
|
81 | - */ |
|
82 | - public function logSpeed($name = 'Point in Time') |
|
83 | - { |
|
84 | - array_push($this->store, array( |
|
85 | - 'data' => microtime(true), |
|
86 | - 'name' => $name, |
|
87 | - 'type' => 'speed' |
|
88 | - )); |
|
89 | - } |
|
77 | + /** |
|
78 | + * Logs current time with optional message |
|
79 | + * |
|
80 | + * @param string $name |
|
81 | + */ |
|
82 | + public function logSpeed($name = 'Point in Time') |
|
83 | + { |
|
84 | + array_push($this->store, array( |
|
85 | + 'data' => microtime(true), |
|
86 | + 'name' => $name, |
|
87 | + 'type' => 'speed' |
|
88 | + )); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Returns the collected logs |
|
93 | - * |
|
94 | - * @returns array |
|
95 | - */ |
|
96 | - public function getLogs() |
|
97 | - { |
|
98 | - return $this->store; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Returns the collected logs |
|
93 | + * |
|
94 | + * @returns array |
|
95 | + */ |
|
96 | + public function getLogs() |
|
97 | + { |
|
98 | + return $this->store; |
|
99 | + } |
|
100 | 100 | } |
@@ -5,112 +5,112 @@ |
||
5 | 5 | class ConsoleTest extends PHPUnit_Framework_TestCase |
6 | 6 | { |
7 | 7 | |
8 | - public function __construct() |
|
9 | - { |
|
10 | - } |
|
11 | - |
|
12 | - public function testLog() |
|
13 | - { |
|
14 | - $data = array( |
|
15 | - 'key' => 'value' |
|
16 | - ); |
|
17 | - |
|
18 | - $console = new Console(); |
|
19 | - $console->log($data); |
|
20 | - $store = $this->getProtectedStore($console); |
|
21 | - $log = array_pop($store); |
|
22 | - |
|
23 | - $this->assertSame($data, $log['data']); |
|
24 | - $this->assertEquals('log', $log['type']); |
|
25 | - } |
|
26 | - |
|
27 | - public function testLogMemory() |
|
28 | - { |
|
29 | - $data = array( |
|
30 | - 'key' => 'value' |
|
31 | - ); |
|
32 | - $memory = strlen(serialize($data)); |
|
33 | - $name = 'Test Array'; |
|
34 | - |
|
35 | - $console = new Console(); |
|
36 | - $console->logMemory($data, $name); |
|
37 | - $store = $this->getProtectedStore($console); |
|
38 | - $log = array_pop($store); |
|
39 | - |
|
40 | - $this->assertEquals($name, $log['name']); |
|
41 | - $this->assertEquals($memory, $log['data']); |
|
42 | - $this->assertEquals('array', $log['data_type']); |
|
43 | - $this->assertEquals('memory', $log['type']); |
|
44 | - } |
|
45 | - |
|
46 | - public function testLogError() |
|
47 | - { |
|
48 | - $error = new Exception('Test Exception'); |
|
49 | - |
|
50 | - $console = new Console(); |
|
51 | - $console->logError($error); |
|
52 | - $store = $this->getProtectedStore($console); |
|
53 | - $log = array_pop($store); |
|
54 | - |
|
55 | - $this->assertEquals($error->getMessage(), $log['data']); |
|
56 | - $this->assertEquals($error->getFile(), $log['file']); |
|
57 | - $this->assertEquals($error->getLine(), $log['line']); |
|
58 | - $this->assertEquals('error', $log['type']); |
|
59 | - |
|
60 | - $error = new Exception('Test Exception'); |
|
61 | - $message = 'override message'; |
|
62 | - |
|
63 | - $console = new Console(); |
|
64 | - $console->logError($error, $message); |
|
65 | - $store = $this->getProtectedStore($console); |
|
66 | - $log = array_pop($store); |
|
67 | - |
|
68 | - $this->assertEquals($message, $log['data']); |
|
69 | - } |
|
70 | - |
|
71 | - public function testLogSpeed() |
|
72 | - { |
|
73 | - $name = 'Test Speed'; |
|
74 | - |
|
75 | - $console = new Console(); |
|
76 | - $console->logSpeed($name); |
|
77 | - $store = $this->getProtectedStore($console); |
|
78 | - $log = array_pop($store); |
|
79 | - |
|
80 | - $this->assertEquals($name, $log['name']); |
|
81 | - $this->assertEquals('speed', $log['type']); |
|
82 | - } |
|
83 | - |
|
84 | - public function testGetLogs() |
|
85 | - { |
|
86 | - $store = array( |
|
87 | - array( |
|
88 | - 'data' => 'a string', |
|
89 | - 'type' => 'log' |
|
90 | - ), |
|
91 | - array( |
|
92 | - 'name' => '', |
|
93 | - 'data' => 123, |
|
94 | - 'data_type' => 'array', |
|
95 | - 'type' => 'memory' |
|
96 | - ) |
|
97 | - ); |
|
98 | - |
|
99 | - $console = new Console(); |
|
100 | - |
|
101 | - $reflectedConsole = new ReflectionClass(get_class($console)); |
|
102 | - $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
103 | - $reflectedProperty->setAccessible(true); |
|
104 | - $reflectedProperty->setValue($console, $store); |
|
105 | - |
|
106 | - $this->assertSame($store, $console->getLogs()); |
|
107 | - } |
|
108 | - |
|
109 | - protected function getProtectedStore(Console $console) |
|
110 | - { |
|
111 | - $reflectedConsole = new ReflectionClass(get_class($console)); |
|
112 | - $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
113 | - $reflectedProperty->setAccessible(true); |
|
114 | - return $reflectedProperty->getValue($console); |
|
115 | - } |
|
8 | + public function __construct() |
|
9 | + { |
|
10 | + } |
|
11 | + |
|
12 | + public function testLog() |
|
13 | + { |
|
14 | + $data = array( |
|
15 | + 'key' => 'value' |
|
16 | + ); |
|
17 | + |
|
18 | + $console = new Console(); |
|
19 | + $console->log($data); |
|
20 | + $store = $this->getProtectedStore($console); |
|
21 | + $log = array_pop($store); |
|
22 | + |
|
23 | + $this->assertSame($data, $log['data']); |
|
24 | + $this->assertEquals('log', $log['type']); |
|
25 | + } |
|
26 | + |
|
27 | + public function testLogMemory() |
|
28 | + { |
|
29 | + $data = array( |
|
30 | + 'key' => 'value' |
|
31 | + ); |
|
32 | + $memory = strlen(serialize($data)); |
|
33 | + $name = 'Test Array'; |
|
34 | + |
|
35 | + $console = new Console(); |
|
36 | + $console->logMemory($data, $name); |
|
37 | + $store = $this->getProtectedStore($console); |
|
38 | + $log = array_pop($store); |
|
39 | + |
|
40 | + $this->assertEquals($name, $log['name']); |
|
41 | + $this->assertEquals($memory, $log['data']); |
|
42 | + $this->assertEquals('array', $log['data_type']); |
|
43 | + $this->assertEquals('memory', $log['type']); |
|
44 | + } |
|
45 | + |
|
46 | + public function testLogError() |
|
47 | + { |
|
48 | + $error = new Exception('Test Exception'); |
|
49 | + |
|
50 | + $console = new Console(); |
|
51 | + $console->logError($error); |
|
52 | + $store = $this->getProtectedStore($console); |
|
53 | + $log = array_pop($store); |
|
54 | + |
|
55 | + $this->assertEquals($error->getMessage(), $log['data']); |
|
56 | + $this->assertEquals($error->getFile(), $log['file']); |
|
57 | + $this->assertEquals($error->getLine(), $log['line']); |
|
58 | + $this->assertEquals('error', $log['type']); |
|
59 | + |
|
60 | + $error = new Exception('Test Exception'); |
|
61 | + $message = 'override message'; |
|
62 | + |
|
63 | + $console = new Console(); |
|
64 | + $console->logError($error, $message); |
|
65 | + $store = $this->getProtectedStore($console); |
|
66 | + $log = array_pop($store); |
|
67 | + |
|
68 | + $this->assertEquals($message, $log['data']); |
|
69 | + } |
|
70 | + |
|
71 | + public function testLogSpeed() |
|
72 | + { |
|
73 | + $name = 'Test Speed'; |
|
74 | + |
|
75 | + $console = new Console(); |
|
76 | + $console->logSpeed($name); |
|
77 | + $store = $this->getProtectedStore($console); |
|
78 | + $log = array_pop($store); |
|
79 | + |
|
80 | + $this->assertEquals($name, $log['name']); |
|
81 | + $this->assertEquals('speed', $log['type']); |
|
82 | + } |
|
83 | + |
|
84 | + public function testGetLogs() |
|
85 | + { |
|
86 | + $store = array( |
|
87 | + array( |
|
88 | + 'data' => 'a string', |
|
89 | + 'type' => 'log' |
|
90 | + ), |
|
91 | + array( |
|
92 | + 'name' => '', |
|
93 | + 'data' => 123, |
|
94 | + 'data_type' => 'array', |
|
95 | + 'type' => 'memory' |
|
96 | + ) |
|
97 | + ); |
|
98 | + |
|
99 | + $console = new Console(); |
|
100 | + |
|
101 | + $reflectedConsole = new ReflectionClass(get_class($console)); |
|
102 | + $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
103 | + $reflectedProperty->setAccessible(true); |
|
104 | + $reflectedProperty->setValue($console, $store); |
|
105 | + |
|
106 | + $this->assertSame($store, $console->getLogs()); |
|
107 | + } |
|
108 | + |
|
109 | + protected function getProtectedStore(Console $console) |
|
110 | + { |
|
111 | + $reflectedConsole = new ReflectionClass(get_class($console)); |
|
112 | + $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
113 | + $reflectedProperty->setAccessible(true); |
|
114 | + return $reflectedProperty->getValue($console); |
|
115 | + } |
|
116 | 116 | } |