| Conditions | 4 |
| Paths | 2 |
| Total Lines | 20 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 47 | protected function parse(): Collection |
|
| 35 | { |
||
| 36 | 47 | $name = $this->metric->key(); |
|
| 37 | 47 | $labels = $this->metric->labels()->toArray(); |
|
| 38 | |||
| 39 | 47 | if (empty($labels) && $this->items->isEmpty()) { |
|
| 40 | 4 | return (new Collection) |
|
| 41 | 4 | ->push(['value' => 0] + compact('name', 'labels')); |
|
| 42 | } |
||
| 43 | |||
| 44 | return $this |
||
| 45 | 43 | ->items |
|
| 46 | // TODO: Find out how to make this an arrow function.. compact doesnt work with outer scoped $name variable |
||
| 47 | 43 | ->map(function ($value, string $field) use ($name) { |
|
| 48 | // Merge stored fields with the value and name to an array. |
||
| 49 | 43 | return compact('name', 'value') + json_decode($field, true); |
|
| 50 | 43 | })->reject(fn(array $data) => !array_key_exists('labels', $data) ?: array_keys($data['labels']) !== $labels) |
|
| 51 | // Filter out items lacking the key "labels" or where labels names don't match. |
||
| 52 | 43 | ->sortBy('labels') |
|
| 53 | 43 | ->values(); |
|
| 54 | } |
||
| 56 |