statisticsDao = $statisticsDao; } #[\Override] public function prepare(Account $account, array $incomingMailboxes, array $outgoingMailboxes, array $messages): void { $senders = array_unique(array_map(static fn (Message $message) => $message->getFrom()->first()->getEmail(), array_filter($messages, static fn (Message $message) => $message->getFrom()->first() !== null && $message->getFrom()->first()->getEmail() !== null))); $this->messagesSentTotal = $this->statisticsDao->getMessagesTotal(...$outgoingMailboxes); $this->messagesSent = $this->statisticsDao->getMessagesSentToGrouped($outgoingMailboxes, $senders); } #[\Override] public function extract(Message $message): array { $sender = $message->getFrom()->first(); if ($sender === null) { throw new RuntimeException('This should not happen'); } $email = $sender->getEmail(); if (($messagesSentTotal = $this->messagesSentTotal) === 0) { // Prevent div by 0 return [0]; } return [($this->messagesSent[$email] ?? 0) / $messagesSentTotal]; } }