| Conditions | 8 |
| Paths | 11 |
| Total Lines | 69 |
| Code Lines | 47 |
| 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 |
||
| 67 | protected function collectData(TimeDataCollector $timeCollector = null) |
||
| 68 | { |
||
| 69 | $stmts = array(); |
||
| 70 | |||
| 71 | $total_duration = 0; |
||
| 72 | $total_mem = 0; |
||
| 73 | |||
| 74 | $failed = 0; |
||
| 75 | |||
| 76 | $i = 0; |
||
| 77 | $queries = $this->db->getQueries(); |
||
| 78 | |||
| 79 | $limit = DebugBar::config()->query_limit; |
||
| 80 | $warnDurationThreshold = Config::inst()->get('DebugBar', 'warn_dbqueries_threshold_seconds'); |
||
| 81 | |||
| 82 | $showDb = count(array_unique(array_map(function ($stmt) { |
||
| 83 | return $stmt['database']; |
||
| 84 | }, $queries))) > 1; |
||
| 85 | |||
| 86 | foreach ($queries as $stmt) { |
||
| 87 | $i++; |
||
| 88 | |||
| 89 | $total_duration += $stmt['duration']; |
||
| 90 | $total_mem += $stmt['memory']; |
||
| 91 | |||
| 92 | if (!$stmt['success']) { |
||
| 93 | $failed++; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($limit && $i > $limit) { |
||
| 97 | $stmts[] = array( |
||
| 98 | 'sql' => "Only the first $limit queries are shown" |
||
| 99 | ); |
||
| 100 | break; |
||
| 101 | } |
||
| 102 | |||
| 103 | $stmts[] = array( |
||
| 104 | 'sql' => $stmt['short_query'], |
||
| 105 | 'row_count' => $stmt['rows'], |
||
| 106 | 'params' => $stmt['select'] ? $stmt['select'] : null, |
||
| 107 | 'duration' => $stmt['duration'], |
||
| 108 | 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), |
||
| 109 | 'memory' => $stmt['memory'], |
||
| 110 | 'memory_str' => $this->getDataFormatter()->formatBytes($stmt['memory']), |
||
| 111 | 'is_success' => $stmt['success'], |
||
| 112 | 'database' => $showDb ? $stmt['database'] : null, |
||
| 113 | 'source' => $stmt['source'], |
||
| 114 | 'warn' => $stmt['duration'] > $warnDurationThreshold |
||
| 115 | ); |
||
| 116 | |||
| 117 | if ($timeCollector !== null) { |
||
| 118 | $timeCollector->addMeasure( |
||
| 119 | $stmt['short_query'], |
||
| 120 | $stmt['start_time'], |
||
| 121 | $stmt['end_time'] |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | return array( |
||
| 127 | 'nb_statements' => count($queries), |
||
| 128 | 'nb_failed_statements' => $failed, |
||
| 129 | 'statements' => $stmts, |
||
| 130 | 'accumulated_duration' => $total_duration, |
||
| 131 | 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($total_duration), |
||
| 132 | 'memory_usage' => $total_mem, |
||
| 133 | 'memory_usage_str' => $this->getDataFormatter()->formatBytes($total_mem), |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | |||
| 177 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.