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 |
||
72 | protected function collectData(TimeDataCollector $timeCollector = null) |
||
73 | { |
||
74 | $stmts = array(); |
||
75 | |||
76 | $total_duration = 0; |
||
77 | $total_mem = 0; |
||
78 | |||
79 | $failed = 0; |
||
80 | |||
81 | $i = 0; |
||
82 | $queries = $this->db->getQueries(); |
||
83 | |||
84 | $limit = DebugBar::config()->query_limit; |
||
85 | $warnDurationThreshold = Config::inst()->get(DebugBar::class, 'warn_dbqueries_threshold_seconds'); |
||
86 | |||
87 | $showDb = count(array_unique(array_map(function ($stmt) { |
||
88 | return $stmt['database']; |
||
89 | }, $queries))) > 1; |
||
90 | |||
91 | foreach ($queries as $stmt) { |
||
92 | $i++; |
||
93 | |||
94 | $total_duration += $stmt['duration']; |
||
95 | $total_mem += $stmt['memory']; |
||
96 | |||
97 | if (!$stmt['success']) { |
||
98 | $failed++; |
||
99 | } |
||
100 | |||
101 | if ($limit && $i > $limit) { |
||
102 | $stmts[] = array( |
||
103 | 'sql' => "Only the first $limit queries are shown" |
||
104 | ); |
||
105 | break; |
||
106 | } |
||
107 | |||
108 | $stmts[] = array( |
||
109 | 'sql' => $stmt['short_query'], |
||
110 | 'row_count' => $stmt['rows'], |
||
111 | 'params' => $stmt['select'] ? $stmt['select'] : null, |
||
112 | 'duration' => $stmt['duration'], |
||
113 | 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), |
||
114 | 'memory' => $stmt['memory'], |
||
115 | 'memory_str' => $this->getDataFormatter()->formatBytes($stmt['memory']), |
||
116 | 'is_success' => $stmt['success'], |
||
117 | 'database' => $showDb ? $stmt['database'] : null, |
||
118 | 'source' => $stmt['source'], |
||
119 | 'warn' => $stmt['duration'] > $warnDurationThreshold |
||
120 | ); |
||
121 | |||
122 | if ($timeCollector !== null) { |
||
123 | $timeCollector->addMeasure( |
||
124 | $stmt['short_query'], |
||
125 | $stmt['start_time'], |
||
126 | $stmt['end_time'] |
||
127 | ); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | return array( |
||
132 | 'nb_statements' => count($queries), |
||
133 | 'nb_failed_statements' => $failed, |
||
134 | 'statements' => $stmts, |
||
135 | 'accumulated_duration' => $total_duration, |
||
136 | 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($total_duration), |
||
137 | 'memory_usage' => $total_mem, |
||
138 | 'memory_usage_str' => $this->getDataFormatter()->formatBytes($total_mem), |
||
139 | ); |
||
140 | } |
||
141 | |||
182 |
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..