applicationId = self::normalizeRequired( 'applicationId', $applicationId ); $this->accessKey = self::normalizeRequired( 'accessKey', $accessKey ); $this->affiliateId = self::normalizeRequired( 'affiliateId', $affiliateId ); } /** * Rakuten Application ID per §9.2 "必須". * * Returned verbatim — the value is the canonical form supplied * to the constructor, with surrounding whitespace already * trimmed off. Provider implementations that build a request * pass this directly to the `applicationId` query parameter * via {@see \Affilun\Domain\Http\HttpRequest::withQueryParameter()}. */ public function applicationId(): string { return $this->applicationId; } /** * Rakuten Access Key required by the current API. */ public function accessKey(): string { return $this->accessKey; } /** * Rakuten Affiliate ID per §9.2 "必須". * * Returned verbatim. Provider implementations append this to * affiliate-tracked URLs and to search-request query strings * when the request shape supports it. */ public function affiliateId(): string { return $this->affiliateId; } /** * Validate and normalize a required credential field at * construction. * * Trims surrounding whitespace and rejects the result when it * is the empty string. The error message names the field * (`applicationId` / `accessKey` / `affiliateId`) so a misconfiguration * surfaces with enough context to fix without dumping the * raw value — per the §10.1 secret-material rule, the value * itself MUST NOT appear in the message. * * @param string $field Field name for the error message. * @param string $value Raw value as supplied by the caller. * * @throws InvalidArgumentException When `$value` is empty * after trimming. */ private static function normalizeRequired( string $field, string $value ): string { $trimmed = trim( $value ); if ( $trimmed === '' ) { $message = sprintf( 'RakutenCredentials %s must be a non-empty string.', $field ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Developer-facing message, never rendered to HTML. throw new InvalidArgumentException( $message ); } return $trimmed; } }