Example #1
0
 /**
  * Function to transform text that satisfies the class description.
  * @param Text $text
  * @return string
  */
 public function transform(Text $text) : string
 {
     $text->setWordsByText($text->getText());
     /** @var Word $word */
     foreach ($text->getWords() as &$word) {
         # Catch words smaller or equal to maxCharsInWord and not numeric
         if ($word->isNumeric() || count($word->getChars()) > $this->maxCharsInWord) {
             continue;
         }
         # Find all capitals and lower string
         $word->findCapitalPositions();
         # Reverse the word
         $word->reverse();
         # Lower the string
         $word->toLowerCase();
         # Reset capitals on the old positions
         $word->setCapitals();
     }
     return $text->buildTextFromWords();
 }
Example #2
0
 /**
  * Function to transform text that satisfies the class description.
  * @param Text $text
  * @return string
  */
 public function transform(Text $text) : string
 {
     $text->setWordsByText($text->getText());
     $words = $text->getWords();
     /** @var Word $word */
     foreach ($words as &$word) {
         # Catch words not numeric
         if ($word->isNumeric()) {
             continue;
         }
         # First find punctuations so they are stored
         $word->findPunctuations();
         # Remove punctuations
         $word->removePunctuations();
         # Store and remove first and last char
         $wordChars = $word->getChars();
         $firstChar = reset($wordChars);
         $lastChar = end($wordChars);
         $word->removeFirstChar();
         $word->removeLastChar();
         # Shuffle the chars that are left
         $word->shuffleChars();
         # Add first and last char
         $word->addCharToFront($firstChar);
         $word->addCharToEnd($lastChar);
         # Reset stripped punctuations
         $word->resetPunctuations();
     }
     $text->setWords($words);
     return $text->buildTextFromWords();
 }
Example #3
0
 /**
  * Function to transform text that satisfies the class description.
  * @param Text $text
  * @return string
  */
 public function transform(Text $text) : string
 {
     $chars = $text->getCharsByText();
     $asciiChars = [];
     foreach ($chars as $key => $char) {
         $asciiChars[$key] = $this->uni_ord($char);
         # Skip first char, has no predecessor
         if ($key == 0) {
             continue;
         }
         # Smaller then predecessor
         if ($asciiChars[$key] < $asciiChars[$key - 1]) {
             $nextAsciiChar = $this->uni_chr($asciiChars[$key] + 1);
             $chars[$key] = $nextAsciiChar;
         }
         # Greater then predecessor
         if ($asciiChars[$key] > $asciiChars[$key - 1]) {
             $nextAsciiChar = $this->uni_chr($asciiChars[$key] + -1);
             $chars[$key] = $nextAsciiChar;
         }
     }
     $text->setChars($chars);
     return $text->buildTextFromChars();
 }
Example #4
0
 /**
  * Function to transform text that satisfies the class description.
  * @param Text $text
  * @return string
  */
 public function transform(Text $text) : string
 {
     $text->setWordsByText($text->getText());
     /** @var Word $word */
     $words = $text->getWords();
     foreach ($words as $key => &$word) {
         # Skip numeric words
         if ($word->isNumeric()) {
             continue;
         }
         # Every X Steps do something :)
         if (($key + 1) % $this->wordSteps == 0) {
             /** @var Word $prevWord */
             $prevWord = $text->getWords()[$key - 1];
             # When punctuation is found, swap it!
             if (count($prevWord->getChars()) > 1) {
                 $prevWordPunctuations = $prevWord->findPunctuations();
                 if (count($prevWordPunctuations[0])) {
                     $this->swapPunctuations($prevWord, $word);
                 }
             }
             # When punctuation is found, swap it!
             if (count($word->getChars()) > 1) {
                 $wordPunctuations = $word->findPunctuations();
                 if (count($wordPunctuations[0])) {
                     $this->swapPunctuations($word, $prevWord);
                 }
             }
             # Find all capitals and lower string
             $word->findCapitalPositions();
             # Reverse the word
             $word->reverse();
             # Lower the string
             $word->toLowerCase();
             # Reset capitals on the old positions
             $word->setCapitals();
             # Swap previous word with current
             $words[$key - 1] = $word;
             $words[$key] = $prevWord;
         }
     }
     $text->setWords($words);
     return $text->buildTextFromWords();
 }