title = $this->empty_to_null( $title ); $this->description = $this->empty_to_null( $description ); $this->canonical = $this->empty_to_null( $canonical ); $this->robots = $this->empty_to_null( $robots ); } /** * Get computed title. */ public function get_title(): ?string { return $this->title; } /** * Get computed description. */ public function get_description(): ?string { return $this->description; } /** * Get canonical URL. */ public function get_canonical(): ?string { return $this->canonical; } /** * Get robots directive. */ public function get_robots(): ?string { return $this->robots; } /** * Export value object as associative array. * * @return array */ public function to_array(): array { return array( 'title' => $this->get_title(), 'description' => $this->get_description(), 'canonical' => $this->get_canonical(), 'robots' => $this->get_robots(), ); } /** * Normalize empty strings to null. * * @param string|null $value Arbitrary value. * * @return string|null */ private function empty_to_null( ?string $value ): ?string { if ( null === $value ) { return null; } $trimmed = trim( $value ); return '' === $trimmed ? null : $trimmed; } }