settings_store->load(); if ( ! $settings->email_enabled ) { return 0; } $reported_at = $this->clock->now(); $links = $this->new_broken_links->since( $this->last_report_time->load() ); if ( array() === $links ) { return 0; } $is_sent = $this->mail_sender->send( $this->recipient( $settings ), $this->broken_links_report->subject(), $this->broken_links_report->body( $links ) ); if ( ! $is_sent ) { throw new RuntimeException( 'The broken links report was not sent.' ); } $this->last_report_time->save( $reported_at ); return count( $links ); } private function recipient( Settings $settings ): string { if ( '' !== $settings->email_to ) { return $settings->email_to; } $admin_email = get_option( self::ADMIN_EMAIL_OPTION ); if ( ! is_string( $admin_email ) ) { throw new RuntimeException( 'The site has no administrator email address.' ); } return $admin_email; } }