Move function count_words from musdb into Puqi
Previously, it was a global function in musdb, making Puqi usable only there. It is now a puqi-specific function and removed from musdb, as it had not been in use there otherwise.
This commit is contained in:
		| @@ -101,6 +101,30 @@ final class MDPuqi { | ||||
|     /** @var array<MDPuqiCheckSection> */ | ||||
|     private array $_checkedSections = []; | ||||
| 
 | ||||
|     /** | ||||
|      * Function count words returns a word count | ||||
|      * | ||||
|      * @param string $string String to get word count ffor. | ||||
|      * | ||||
|      * @return integer | ||||
|      */ | ||||
|     private function _count_words(string $string):int { | ||||
| 
 | ||||
|         $string = htmlspecialchars_decode(\strip_tags($string)); | ||||
|         if (empty($string)) return 0; | ||||
|         $t = ['_' => 1, "\x20" => 1, "\xA0" => 1, "\x0A" => 1, "\x0D" => 1, "\x09" => 1, "\x0B" => 1, "\x2E" => 1, '=' => 1, '+' => 1, '-' => 1, '*' => 1, '/' => 1, '\\' => 1, ',' => 1, ';' => 1, ':' => 1, '"' => 1, '\'' => 1, '[' => 1, ']' => 1, '{' => 1, '}' => 1, '(' => 1, ')' => 1, '<' => 1, '>' => 1, '&' => 1, '%' => 1, '$' => 1, '@' => 1, '#' => 1, '^' => 1, '!' => 1, '?' => 1]; // separators
 | ||||
|         $count = isset($t[$string[0]]) ? 0 : 1; | ||||
| 
 | ||||
|         $inpStrLen = strlen($string); | ||||
|         if ($inpStrLen === 1) return $count; | ||||
|         for ($i = 1; $i < $inpStrLen; $i++) { | ||||
|             if (isset($t[$string[$i - 1]]) && !isset($t[$string[$i]])) // if new word starts
 | ||||
|             $count++; | ||||
|         } | ||||
|         return $count; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Marks the object name as a duplicate. | ||||
|      * | ||||
| @@ -146,7 +170,7 @@ final class MDPuqi { | ||||
| 
 | ||||
|         $this->_checkedSections[] = MDPuqiCheckSection::objectName; | ||||
| 
 | ||||
|         $words_in_title = count_words($object_name); | ||||
|         $words_in_title = $this->_count_words($object_name); | ||||
|         if ($words_in_title === 1) { | ||||
| 
 | ||||
|             $this->_messages[] = new MDPuqiMessage( | ||||
| @@ -192,12 +216,12 @@ final class MDPuqi { | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         else if (count_words($object_type) > self::THRESHOLD_WC_OBJECT_TYPE_TOO_LONG) { | ||||
|         else if ($this->_count_words($object_type) > self::THRESHOLD_WC_OBJECT_TYPE_TOO_LONG) { | ||||
| 
 | ||||
|             $this->_messages[] = new MDPuqiMessage( | ||||
|                 MDPuqiCheckSection::objectType, | ||||
|                 MDPuqiMessageStatus::neutral, | ||||
|                 count_words($object_type) . ' ' . $this->_tlLoader->tl("quality", "quality", "many_words_object_type"), | ||||
|                 $this->_count_words($object_type) . ' ' . $this->_tlLoader->tl("quality", "quality", "many_words_object_type"), | ||||
|                 0, | ||||
|             ); | ||||
| 
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user