Ejemplo n.º 1
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();
 }