| Conditions | 4 |
| Paths | 2 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 51 | 47 | protected function parse(): Collection |
|
| 52 | { |
||
| 53 | 47 | $name = $this->metric->key(); |
|
| 54 | 4 | $labels = $this->metric->labels()->toArray(); |
|
| 55 | 4 | ||
| 56 | 4 | if (empty($labels) && $this->items->isEmpty()) { |
|
| 57 | 4 | return (new Collection) |
|
| 58 | ->push(['value' => 0] + compact('name', 'labels')); |
||
| 59 | } |
||
| 60 | |||
| 61 | return $this |
||
| 62 | 43 | ->items |
|
| 63 | ->map(function ($value, string $field) use ($name) { |
||
| 64 | 43 | // Merge stored fields with the value and name to an array. |
|
| 65 | return compact('name', 'value') + json_decode($field, true); |
||
| 66 | 43 | })->reject(function (array $data) use ($labels) { |
|
| 67 | // Filter out items lacking the key "labels" or where labels names don't match. |
||
| 68 | 43 | return !array_key_exists('labels', $data) |
|
| 69 | 43 | ?: array_keys($data['labels']) !== $labels; |
|
| 70 | })->sortBy('labels') |
||
| 71 | ->values(); |
||
| 72 | 42 | } |
|
| 73 | } |
||
| 74 |