vendor/gos/web-socket-bundle/src/DataCollector/WebsocketDataCollector.php line 7

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Gos\Bundle\WebSocketBundle\DataCollector;
  3. use Symfony\Component\Stopwatch\StopwatchEvent;
  4. trigger_deprecation('gos/web-socket-bundle''3.1''The "%s" class is deprecated and will be removed in 4.0.'WebsocketDataCollector::class);
  5. /**
  6.  * @deprecated to be removed in 4.0
  7.  */
  8. final class WebsocketDataCollector extends WebsocketCompatibilityDataCollector
  9. {
  10.     private array $rawData = [];
  11.     public function lateCollect(): void
  12.     {
  13.         $pusherCount = [];
  14.         $totalPush 0;
  15.         $pusherDuration = [];
  16.         $durationTotal 0.0;
  17.         foreach ($this->rawData as $pusherName => $durations) {
  18.             if (!isset($pusherCount[$pusherName])) {
  19.                 $pusherCount[$pusherName] = 0;
  20.             }
  21.             $pusherDurationTotal array_sum($durations);
  22.             $pusherCount[$pusherName] += $count = \count($durations);
  23.             $totalPush += $count;
  24.             $pusherDuration[$pusherName] = $pusherDurationTotal;
  25.             $durationTotal += $pusherDurationTotal;
  26.         }
  27.         $this->data = [
  28.             'pusher_counts' => $pusherCount,
  29.             'push_total' => $totalPush,
  30.             'durations' => $pusherDuration,
  31.             'duration_total' => $durationTotal,
  32.         ];
  33.     }
  34.     /**
  35.      * @return int[]
  36.      */
  37.     public function getPusherCounts(): array
  38.     {
  39.         return $this->data['pusher_counts'];
  40.     }
  41.     public function getTotalDuration(): float
  42.     {
  43.         return $this->data['duration_total'];
  44.     }
  45.     /**
  46.      * @return float[]
  47.      */
  48.     public function getDurations(): array
  49.     {
  50.         return $this->data['durations'];
  51.     }
  52.     public function getPushTotal(): int
  53.     {
  54.         return $this->data['push_total'];
  55.     }
  56.     public function collectData(StopwatchEvent $eventstring $pusherName): void
  57.     {
  58.         if (!isset($this->rawData[$pusherName])) {
  59.             $this->rawData[$pusherName] = [];
  60.         }
  61.         $this->rawData[$pusherName][] = $event->getDuration();
  62.     }
  63.     public function reset(): void
  64.     {
  65.         $this->rawData = [];
  66.         $this->data = [
  67.             'pusher_counts' => [],
  68.             'push_total' => 0,
  69.             'durations' => [],
  70.             'duration_total' => 0,
  71.         ];
  72.     }
  73.     public function getName(): string
  74.     {
  75.         return 'websocket';
  76.     }
  77. }