| Conditions | 15 |
| Paths | 136 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 169 | private function exporting(bool $push = false) : string |
||
| 170 | { |
||
| 171 | $now = $push ? 0 : (int)(microtime(true) * 1000); |
||
| 172 | |||
| 173 | $lines = $types = []; |
||
| 174 | |||
| 175 | foreach ($this->agg->metrics() as $typed => $metrics) { |
||
| 176 | foreach ($metrics as $named => $groups) { |
||
| 177 | foreach ($groups as $grouped => $stack) { |
||
| 178 | $named = $this->format($named); |
||
| 179 | |||
| 180 | list($data, $labels, $description) = $stack; |
||
| 181 | |||
| 182 | $types[$named] = $typed; |
||
| 183 | $description && $lines[] = sprintf('# HELP %s %s', $named, $description); |
||
| 184 | |||
| 185 | if (in_array($typed, [Metrical::COUNTER, Metrical::GAUGE])) { |
||
| 186 | $lines[] = sprintf('%s{%s} %g', $named, $this->labeled($labels), $data['value']) |
||
| 187 | . ($now ? sprintf(' %d', $now) : '') |
||
| 188 | ; |
||
| 189 | } elseif (in_array($typed, [Metrical::HISTOGRAM, Metrical::SUMMARY])) { |
||
| 190 | $lines[] = sprintf('%s_sum{%s} %g', $named, $this->labeled($labels), $data['sum']); |
||
| 191 | $lines[] = sprintf('%s_count{%s} %d', $named, $this->labeled($labels), $data['count']); |
||
| 192 | if ($typed === Metrical::HISTOGRAM) { |
||
| 193 | foreach ($data['buckets'] as $bucket) { |
||
| 194 | list($bound, $observed) = $bucket; |
||
| 195 | $lines[] = sprintf( |
||
| 196 | '%s_bucket{%s} %d', |
||
| 197 | $named, |
||
| 198 | $this->labeled($labels, ['le' => $bound]), |
||
| 199 | $observed |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | } elseif ($typed === Metrical::SUMMARY) { |
||
| 203 | foreach ($data['quantiles'] as $quantile) { |
||
| 204 | list($position, $value) = $quantile; |
||
| 205 | $lines[] = sprintf( |
||
| 206 | '%s{%s} %g', |
||
| 207 | $named, |
||
| 208 | $this->labeled($labels, ['quantile' => $position]), |
||
| 209 | $value |
||
| 210 | ); |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | foreach ($types as $named => $typed) { |
||
| 219 | array_unshift($lines, sprintf('# TYPE %s %s', $named, $typed)); |
||
| 220 | } |
||
| 221 | |||
| 222 | $push && $lines[] = ''; |
||
| 223 | |||
| 224 | return implode("\n", $lines); |
||
| 225 | } |
||
| 257 |