brand() !== null ) { $parts[] = $snapshot->brand(); } $parts[] = $snapshot->title(); return new SearchKeywordsExtractionResult( $this->truncate( implode( ' ', $parts ), 512 ), 'fallback_title' ); } /** * Bound keywords to the DB column size. * * @param string $value Raw keywords. * @param int $max Maximum length. */ private function truncate( string $value, int $max ): string { $normalized = trim( preg_replace( '/\s+/u', ' ', $value ) ?? $value ); if ( function_exists( 'mb_substr' ) ) { return mb_substr( $normalized, 0, $max, 'UTF-8' ); } return substr( $normalized, 0, $max ); } }