public function isLinkSpam(string $text) : bool
{
$urlPattern = '~((ftp|http|https)://)?[\\-\\w]+(\\.[\\-\\w]+)*\\.[a-z]{2,6}~i';
$linkCount = preg_match_all($urlPattern, $text, $matches);
if (self::LINK_MAX_COUNT <= $linkCount) {
// More links than allowed
return true;
}
$wordCount = preg_match_all('~[\\pZ\\s]+~u', trim($text), $matches) + 1;
if (self::LINK_WORDS_MIN_COUNT >= $wordCount) {
// For short texts use links count check
return self::LINK_SHORT_MAX_COUNT <= $linkCount;
}
// For long texts check links ratio
return self::LINK_MAX_RATIO <= $linkCount / $wordCount;
}