stats = $stats; $this->mailStatus = $mailStatus; $this->clock = $clock ?? 'time'; } /** * The report, or null when there is nothing worth saying. * * @return array{days: int, total: int, unconfirmed: int, share: int, mailFailed: int}|null */ public function report(): ?array { $now = (int) call_user_func( $this->clock ); $window = $this->stats->confirmationWindow( $now - self::WINDOW_DAYS * 86400, $now - self::GRACE_SECONDS ); if ( $window['total'] < self::MIN_OPTINS ) { return null; } $share = (int) round( $window['unconfirmed'] * 100 / $window['total'] ); if ( $share < self::MIN_SHARE ) { return null; } return array( 'days' => self::WINDOW_DAYS, 'total' => $window['total'], 'unconfirmed' => $window['unconfirmed'], 'share' => $share, 'mailFailed' => $this->mailStatus->countFailedSince( self::WINDOW_DAYS * 86400 ), ); } /** * `f12_doi_rest_dashboard_stats`: add `stuckOptins`. * * @param mixed $data Dashboard payload. * * @return mixed */ public function addToDashboard( $data ) { if ( is_array( $data ) ) { $data['stuckOptins'] = $this->report(); } return $data; } }