spamRegex = $spamRegex; $this->summaryRegex = $summaryRegex; } /** * Check whether content text is considered spam * * @param string $text * @return bool|string Matching string or false */ public function checkContent( string $text ) { return self::checkInternal( $text, $this->spamRegex ); } /** * Check whether summary text is considered spam * * @param string $summary * @return bool|string Matching string or false */ public function checkSummary( string $summary ) { return self::checkInternal( $summary, $this->summaryRegex ); } /** * @param string $text * @param array $regexes * @return bool|string */ private static function checkInternal( string $text, array $regexes ) { foreach ( $regexes as $regex ) { $matches = []; if ( preg_match( $regex, $text, $matches ) ) { return $matches[0]; } } return false; } }