| Conditions | 23 |
| Paths | 32 |
| Total Lines | 329 |
| Code Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 23 | public function __invoke($output) |
||
| 24 | { |
||
| 25 | |||
| 26 | $css = file_get_contents(__DIR__ . '/../css/pQp.css'); |
||
| 27 | |||
| 28 | echo <<<JAVASCRIPT |
||
| 29 | <!-- JavaScript --> |
||
| 30 | <script type="text/javascript"> |
||
| 31 | var PQP_DETAILS = true; |
||
| 32 | var PQP_HEIGHT = "short"; |
||
| 33 | |||
| 34 | function changeTab(tab) { |
||
| 35 | var pQp = document.getElementById('pQp'); |
||
| 36 | hideAllTabs(); |
||
| 37 | addClassName(pQp, tab, true); |
||
| 38 | } |
||
| 39 | |||
| 40 | function hideAllTabs() { |
||
| 41 | var pQp = document.getElementById('pQp'); |
||
| 42 | removeClassName(pQp, 'console'); |
||
| 43 | removeClassName(pQp, 'speed'); |
||
| 44 | removeClassName(pQp, 'queries'); |
||
| 45 | removeClassName(pQp, 'memory'); |
||
| 46 | removeClassName(pQp, 'files'); |
||
| 47 | } |
||
| 48 | |||
| 49 | function toggleDetails(){ |
||
| 50 | var container = document.getElementById('pqp-container'); |
||
| 51 | |||
| 52 | if(PQP_DETAILS){ |
||
| 53 | addClassName(container, 'hideDetails', true); |
||
| 54 | PQP_DETAILS = false; |
||
| 55 | } |
||
| 56 | else{ |
||
| 57 | removeClassName(container, 'hideDetails'); |
||
| 58 | PQP_DETAILS = true; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | function toggleHeight(){ |
||
| 62 | var container = document.getElementById('pqp-container'); |
||
| 63 | |||
| 64 | if(PQP_HEIGHT == "short"){ |
||
| 65 | addClassName(container, 'tallDetails', true); |
||
| 66 | PQP_HEIGHT = "tall"; |
||
| 67 | } |
||
| 68 | else{ |
||
| 69 | removeClassName(container, 'tallDetails'); |
||
| 70 | PQP_HEIGHT = "short"; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | setTimeout(function(){document.getElementById("pqp-container").style.display = "block"}, 10); |
||
| 75 | |||
| 76 | //http://www.bigbold.com/snippets/posts/show/2630 |
||
| 77 | function addClassName(objElement, strClass, blnMayAlreadyExist){ |
||
| 78 | if ( objElement.className ){ |
||
| 79 | var arrList = objElement.className.split(' '); |
||
| 80 | if ( blnMayAlreadyExist ){ |
||
| 81 | var strClassUpper = strClass.toUpperCase(); |
||
| 82 | for ( var i = 0; i < arrList.length; i++ ){ |
||
| 83 | if ( arrList[i].toUpperCase() == strClassUpper ){ |
||
| 84 | arrList.splice(i, 1); |
||
| 85 | i--; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | arrList[arrList.length] = strClass; |
||
| 90 | objElement.className = arrList.join(' '); |
||
| 91 | } |
||
| 92 | else{ |
||
| 93 | objElement.className = strClass; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | //http://www.bigbold.com/snippets/posts/show/2630 |
||
| 98 | function removeClassName(objElement, strClass){ |
||
| 99 | if ( objElement.className ){ |
||
| 100 | var arrList = objElement.className.split(' '); |
||
| 101 | var strClassUpper = strClass.toUpperCase(); |
||
| 102 | for ( var i = 0; i < arrList.length; i++ ){ |
||
| 103 | if ( arrList[i].toUpperCase() == strClassUpper ){ |
||
| 104 | arrList.splice(i, 1); |
||
| 105 | i--; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | objElement.className = arrList.join(' '); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | //http://ejohn.org/projects/flexible-javascript-events/ |
||
| 113 | function addEvent( obj, type, fn ) { |
||
| 114 | if ( obj.attachEvent ) { |
||
| 115 | obj["e"+type+fn] = fn; |
||
| 116 | obj[type+fn] = function() { obj["e"+type+fn]( window.event ) }; |
||
| 117 | obj.attachEvent( "on"+type, obj[type+fn] ); |
||
| 118 | } |
||
| 119 | else{ |
||
| 120 | obj.addEventListener( type, fn, false ); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | </script> |
||
| 124 | JAVASCRIPT; |
||
| 125 | |||
| 126 | echo <<<STYLESHEETS |
||
| 127 | <style type="text/css"> |
||
| 128 | $css |
||
| 129 | </style> |
||
| 130 | STYLESHEETS; |
||
| 131 | |||
| 132 | echo '<div id="pqp-container" class="pQp" style="display:none">'; |
||
| 133 | |||
| 134 | $logCount = count($output['logs']['console']['messages']); |
||
| 135 | $fileCount = count($output['files']); |
||
| 136 | $memoryUsed = $output['memoryTotals']['used']; |
||
| 137 | $queryCount = $output['queryTotals']['count']; |
||
| 138 | $speedTotal = $output['speedTotals']['total']; |
||
| 139 | |||
| 140 | echo <<<PQPTABS |
||
| 141 | <div id="pQp" class="console"> |
||
| 142 | <table id="pqp-metrics" cellspacing="0"> |
||
| 143 | <tr> |
||
| 144 | <td class="green" onclick="changeTab('console');"> |
||
| 145 | <var>$logCount</var> |
||
| 146 | <h4>Console</h4> |
||
| 147 | </td> |
||
| 148 | <td class="blue" onclick="changeTab('speed');"> |
||
| 149 | <var>$speedTotal</var> |
||
| 150 | <h4>Load Time</h4> |
||
| 151 | </td> |
||
| 152 | <td class="purple" onclick="changeTab('queries');"> |
||
| 153 | <var>$queryCount Queries</var> |
||
| 154 | <h4>Database</h4> |
||
| 155 | </td> |
||
| 156 | <td class="orange" onclick="changeTab('memory');"> |
||
| 157 | <var>$memoryUsed</var> |
||
| 158 | <h4>Memory Used</h4> |
||
| 159 | </td> |
||
| 160 | <td class="red" onclick="changeTab('files');"> |
||
| 161 | <var>{$fileCount} Files</var> |
||
| 162 | <h4>Included</h4> |
||
| 163 | </td> |
||
| 164 | </tr> |
||
| 165 | </table> |
||
| 166 | PQPTABS; |
||
| 167 | |||
| 168 | echo '<div id="pqp-console" class="pqp-box">'; |
||
| 169 | |||
| 170 | if($logCount == 0) { |
||
| 171 | echo '<h3>This panel has no log items.</h3>'; |
||
| 172 | } |
||
| 173 | else { |
||
| 174 | $console = $output['logs']['console']; |
||
| 175 | echo '<table class="side" cellspacing="0"> |
||
| 176 | <tr> |
||
| 177 | <td class="alt1"><var>'.$console['totals']['log'].'</var><h4>Logs</h4></td> |
||
| 178 | <td class="alt2"><var>'.$console['totals']['error'].'</var> <h4>Errors</h4></td> |
||
| 179 | </tr> |
||
| 180 | <tr> |
||
| 181 | <td class="alt3"><var>'.$console['totals']['memory'].'</var> <h4>Memory</h4></td> |
||
| 182 | <td class="alt4"><var>'.$console['totals']['speed'].'</var> <h4>Speed</h4></td> |
||
| 183 | </tr> |
||
| 184 | </table> |
||
| 185 | <table class="main" cellspacing="0">'; |
||
| 186 | |||
| 187 | $class = ''; |
||
| 188 | foreach($output['logs']['console']['messages'] as $log) { |
||
| 189 | echo '<tr class="log-'.$log['type'].'"> |
||
| 190 | <td class="type">'.$log['type'].'</td> |
||
| 191 | <td class="'.$class.'">'; |
||
| 192 | if($log['type'] == 'log') { |
||
| 193 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
||
| 194 | } |
||
| 195 | elseif($log['type'] == 'memory') { |
||
| 196 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['data_type'].'</em>: '.$log['name'].' </div>'; |
||
| 197 | } |
||
| 198 | elseif($log['type'] == 'speed') { |
||
| 199 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
||
| 200 | } |
||
| 201 | elseif($log['type'] == 'error') { |
||
| 202 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
||
| 203 | } |
||
| 204 | |||
| 205 | echo '</td></tr>'; |
||
| 206 | if($class == '') $class = 'alt'; |
||
| 207 | else $class = ''; |
||
| 208 | } |
||
| 209 | |||
| 210 | echo '</table>'; |
||
| 211 | } |
||
| 212 | |||
| 213 | echo '</div>'; |
||
| 214 | |||
| 215 | echo '<div id="pqp-speed" class="pqp-box">'; |
||
| 216 | |||
| 217 | if($output['logs']['speedCount'] == 0) { |
||
| 218 | echo '<h3>This panel has no log items.</h3>'; |
||
| 219 | } |
||
| 220 | else { |
||
| 221 | echo '<table class="side" cellspacing="0"> |
||
| 222 | <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr> |
||
| 223 | <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr> |
||
| 224 | </table> |
||
| 225 | <table class="main" cellspacing="0">'; |
||
| 226 | |||
| 227 | $class = ''; |
||
| 228 | foreach($output['logs']['console'] as $log) { |
||
| 229 | if($log['type'] == 'speed') { |
||
| 230 | echo '<tr class="log-'.$log['type'].'"> |
||
| 231 | <td class="'.$class.'">'; |
||
| 232 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
||
| 233 | echo '</td></tr>'; |
||
| 234 | if($class == '') $class = 'alt'; |
||
| 235 | else $class = ''; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | echo '</table>'; |
||
| 240 | } |
||
| 241 | |||
| 242 | echo '</div>'; |
||
| 243 | |||
| 244 | echo '<div id="pqp-queries" class="pqp-box">'; |
||
| 245 | |||
| 246 | if($output['queryTotals']['count'] == 0) { |
||
| 247 | echo '<h3>This panel has no log items.</h3>'; |
||
| 248 | } |
||
| 249 | else { |
||
| 250 | echo '<table class="side" cellspacing="0"> |
||
| 251 | <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr> |
||
| 252 | <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr> |
||
| 253 | <tr><td><var>0</var> <h4>Duplicates</h4></td></tr> |
||
| 254 | </table> |
||
| 255 | <table class="main" cellspacing="0">'; |
||
| 256 | |||
| 257 | $class = ''; |
||
| 258 | foreach($output['queries'] as $query) { |
||
| 259 | echo '<tr> |
||
| 260 | <td class="'.$class.'">'.$query['sql']; |
||
| 261 | if($query['explain']) { |
||
| 262 | echo '<em> |
||
| 263 | Possible keys: <b>'.$query['explain']['possible_keys'].'</b> · |
||
| 264 | Key Used: <b>'.$query['explain']['key'].'</b> · |
||
| 265 | Type: <b>'.$query['explain']['type'].'</b> · |
||
| 266 | Rows: <b>'.$query['explain']['rows'].'</b> · |
||
| 267 | Speed: <b>'.$query['time'].'</b> |
||
| 268 | </em>'; |
||
| 269 | } |
||
| 270 | echo '</td></tr>'; |
||
| 271 | if($class == '') $class = 'alt'; |
||
| 272 | else $class = ''; |
||
| 273 | } |
||
| 274 | |||
| 275 | echo '</table>'; |
||
| 276 | } |
||
| 277 | |||
| 278 | echo '</div>'; |
||
| 279 | |||
| 280 | echo '<div id="pqp-memory" class="pqp-box">'; |
||
| 281 | |||
| 282 | if($output['logs']['memoryCount'] == 0) { |
||
| 283 | echo '<h3>This panel has no log items.</h3>'; |
||
| 284 | } |
||
| 285 | else { |
||
| 286 | echo '<table class="side" cellspacing="0"> |
||
| 287 | <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr> |
||
| 288 | <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr> |
||
| 289 | </table> |
||
| 290 | <table class="main" cellspacing="0">'; |
||
| 291 | |||
| 292 | $class = ''; |
||
| 293 | foreach($output['logs']['console'] as $log) { |
||
| 294 | if($log['type'] == 'memory') { |
||
| 295 | echo '<tr class="log-'.$log['type'].'">'; |
||
| 296 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>'; |
||
| 297 | echo '</tr>'; |
||
| 298 | if($class == '') $class = 'alt'; |
||
| 299 | else $class = ''; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | echo '</table>'; |
||
| 304 | } |
||
| 305 | |||
| 306 | echo '</div>'; |
||
| 307 | |||
| 308 | echo '<div id="pqp-files" class="pqp-box">'; |
||
| 309 | |||
| 310 | if($output['fileTotals']['count'] == 0) { |
||
| 311 | echo '<h3>This panel has no log items.</h3>'; |
||
| 312 | } |
||
| 313 | else { |
||
| 314 | echo '<table class="side" cellspacing="0"> |
||
| 315 | <tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr> |
||
| 316 | <tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr> |
||
| 317 | <tr><td><var>'.$output['fileTotals']['largest'].'</var> <h4>Largest</h4></td></tr> |
||
| 318 | </table> |
||
| 319 | <table class="main" cellspacing="0">'; |
||
| 320 | |||
| 321 | $class =''; |
||
| 322 | foreach($output['files'] as $file) { |
||
| 323 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
||
| 324 | if($class == '') $class = 'alt'; |
||
| 325 | else $class = ''; |
||
| 326 | } |
||
| 327 | |||
| 328 | echo '</table>'; |
||
| 329 | } |
||
| 330 | |||
| 331 | echo '</div>'; |
||
| 332 | |||
| 333 | echo <<<FOOTER |
||
| 334 | <table id="pqp-footer" cellspacing="0"> |
||
| 335 | <tr> |
||
| 336 | <td class="credit"> |
||
| 337 | <a href="http://particletree.com" target="_blank"> |
||
| 338 | <strong>PHP</strong> |
||
| 339 | <b class="green">Q</b><b class="blue">u</b><b class="purple">i</b><b class="orange">c</b><b class="red">k</b> |
||
| 340 | Profiler</a></td> |
||
| 341 | <td class="actions"> |
||
| 342 | <a href="#" onclick="toggleDetails();return false">Details</a> |
||
| 343 | <a class="heightToggle" href="#" onclick="toggleHeight();return false">Height</a> |
||
| 344 | </td> |
||
| 345 | </tr> |
||
| 346 | </table> |
||
| 347 | FOOTER; |
||
| 348 | |||
| 349 | echo '</div></div>'; |
||
| 350 | |||
| 351 | } |
||
| 352 | } |
||
| 353 |