| Conditions | 7 |
| Paths | 48 |
| Total Lines | 73 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 3 |
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 |
||
| 41 | $metrics[] = [ |
||
| 42 | 'name' => $parts[1], |
||
| 43 | 'help' => '', |
||
| 44 | 'type' => $parts[2], |
||
| 45 | 'value' => $value, |
||
| 46 | 'labels' => $labels, |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | return $metrics; |
||
| 50 | |||
| 51 | } |
||
| 52 | |||
| 53 | public function render() |
||
| 54 | { |
||
| 55 | $defaultLabels = ['application' => $this->config['application']]; |
||
| 56 | $metrics = $this->getMetrics(); |
||
| 57 | $lines = []; |
||
| 58 | foreach ($metrics as $metric) { |
||
| 59 | $lines[] = "# HELP " . $metric['name'] . " {$metric['help']}"; |
||
| 60 | $lines[] = "# TYPE " . $metric['name'] . " {$metric['type']}"; |
||
| 61 | |||
| 62 | $metricLabels = isset($metric['labels']) ? $metric['labels'] : []; |
||
| 63 | $labels = ['{']; |
||
| 64 | $allLabels = array_merge($defaultLabels, $metricLabels); |
||
| 65 | foreach ($allLabels as $key => $value) { |
||
| 66 | $value = addslashes($value); |
||
| 67 | $labels[] = "{$key}=\"{$value}\","; |
||
| 68 | } |
||
| 69 | $labels[] = '}'; |
||
| 70 | $labelStr = implode('', $labels); |
||
| 71 | $lines[] = $metric['name'] . "$labelStr {$metric['value']}"; |
||
| 72 | } |
||
| 73 | return implode("\n", $lines); |
||
| 74 | } |
||
| 75 | } |