owenvoke / laravel-dashboard-cloudflare-stats-tile

A tile for Laravel Dashboard that displays statistics from Cloudflare
https://packagist.org/packages/owenvoke/laravel-dashboard-cloudflare-stats-tile
MIT License
11 stars 2 forks source link

Prevent ErrorException when 0 results #5

Closed juliofagundes closed 4 years ago

juliofagundes commented 4 years ago

Prevent ErrorException when 0 results of valid domains.

  ErrorException 

  Undefined offset: 0

  at vendor/owenvoke/laravel-dashboard-cloudflare-stats-tile/src/Services/Cloudflare.php:48
     44▕             ->flatMap(static function (Collection $item, $key) {
     45▕                 return [
     46▕                     $key => [
     47▕                         'requests' => $item->sum(static function (array $item) {
  ➜  48▕                             return $item['httpRequests1dGroups'][0]['sum']['requests'] ?: 0;
     49▕                         }),
     50▕                         'bytes' => $item->sum(static function (array $item) {
     51▕                             return $item['httpRequests1dGroups'][0]['sum']['bytes'] ?: 0;
     52▕                         }),

      +2 vendor frames 

...