post_id = $post_id; $this->post_type = $post_type; $this->source = $source; $this->phrase = $phrase; $this->stemmed = $stemmed; $this->normalized = $normalized; $this->word_count = $word_count > 0 ? $word_count : self::count_words( $phrase ); $this->row_id = $row_id; $this->checked = $checked; $this->impressions = $impressions; $this->clicks = $clicks; } /** * Counts whitespace-separated words in the given phrase. * * Trivial fallback used when the constructor receives a zero word count. * The full multi-byte counter lives in WordTokenizer; we duplicate the * trivial case here so the model remains free of tokeniser dependencies. * * @since 1.0.0 * * @param string $phrase The phrase to count. * * @return int Word count. */ private static function count_words( string $phrase ): int { $trimmed = trim( $phrase ); if ( '' === $trimmed ) { return 0; } // Split on any run of whitespace. $parts = preg_split( '/\s+/u', $trimmed ); return is_array( $parts ) ? count( $parts ) : 0; } }