logs = $logs; $this->masker = $masker; } /** * Execute the §12.3 logs-summary query. * * Calls {@see LogRepository::countByLevel()} for the level * histogram and {@see LogRepository::findRecent()} for the * recent-entries slice, projects each returned record through * {@see LogMasker::maskRecord()}, and wraps the result in a * {@see GetLogsSummaryResult}. * * @param int $recentLimit Recent-entries limit (1..50). Default 10. * * @throws InvalidArgumentException When `$recentLimit` is out * of the [1, 50] range. */ public function execute( int $recentLimit = self::DEFAULT_RECENT_LIMIT ): GetLogsSummaryResult { if ( $recentLimit < 1 || $recentLimit > self::MAX_RECENT_LIMIT ) { $message = sprintf( 'GetLogsSummaryUseCase: recent_limit must be between 1 and %d, got %d.', self::MAX_RECENT_LIMIT, $recentLimit ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } $counts = $this->logs->countByLevel(); $records = $this->logs->findRecent( $recentLimit ); $recent = array(); foreach ( $records as $record ) { $recent[] = $this->masker->maskRecord( $record ); } return new GetLogsSummaryResult( $counts, $recent ); } }