repository = $repository; } /** * Execute the §8.3 lookup dispatch. * * @param int $id Local product id (1-based auto-increment). * * @return ProductRecord The record matching `$id`. * * @throws InvalidArgumentException When `$id` is below 1. * @throws ProductNotFoundException When no row matches `$id`. */ public function execute( int $id ): ProductRecord { if ( $id < 1 ) { $message = sprintf( 'GetProductUseCase: id must be >= 1; got %d.', $id ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } $record = $this->repository->findById( $id ); if ( $record === null ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw ProductNotFoundException::forId( $id ); } return $record; } }