| Conditions | 4 |
| Paths | 6 |
| Total Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function save(array $data, string $id = null): string |
||
| 17 | { |
||
| 18 | // extract "get" from "url" |
||
| 19 | // profiler no longer needs to send "get" over the wire. |
||
| 20 | // the individual savers may choose not to store this down separately |
||
| 21 | $query = parse_url($data['meta']['url'], PHP_URL_QUERY); |
||
| 22 | parse_str($query, $get); |
||
| 23 | $data['meta']['get'] = $get; |
||
| 24 | |||
| 25 | foreach ($data['profile'] as $index => &$profile) { |
||
| 26 | // skip empty profilings |
||
| 27 | if (!$profile) { |
||
| 28 | unset($data['profile'][$index]); |
||
| 29 | continue; |
||
| 30 | } |
||
| 31 | |||
| 32 | // normalize, fill all missing keys |
||
| 33 | $profile += [ |
||
| 34 | 'ct' => 0, |
||
| 35 | 'wt' => 0, |
||
| 36 | 'cpu' => 0, |
||
| 37 | 'mu' => 0, |
||
| 38 | 'pmu' => 0, |
||
| 39 | ]; |
||
| 40 | } |
||
| 41 | unset($profile); |
||
| 42 | |||
| 43 | if (!$data['profile']) { |
||
| 44 | throw new RuntimeException('Skipping to save empty profiling'); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $this->saver->save($data, $id); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |