예제 #1
0
 /**
  * Determines {@link subtype} of method by name.
  *
  * @param string $methodFullName Name of method
  *
  * @return string Subtype of method (related command),
  *                possible values see {@link subtypesAll}
  */
 static function determineSubtypeByName($methodFullName)
 {
     $resultSubtype = null;
     switch (static::determineTypeByName($methodFullName)) {
         case self::TYPE_ACTION:
             $resultSubtype = Helper::hasPostfix('AndWait', $methodFullName) ? static::SUBTYPE_AND_WAIT : static::SUBTYPE_BASE;
             break;
         case self::TYPE_ACCESSOR:
             $prefix2subtype = ['store' => static::SUBTYPE_STORE, 'get' => static::SUBTYPE_GET, 'is' => static::SUBTYPE_IS];
             foreach ($prefix2subtype as $prefix => $subtype) {
                 // determine by prefix
                 if (Helper::hasPrefix($prefix, $methodFullName)) {
                     $resultSubtype = $subtype;
                 }
             }
             break;
         case self::TYPE_ASSERTION:
             $hasNot = strpos($methodFullName, 'Not') !== false;
             $prefix2subtype = $hasNot ? ['assert' => static::SUBTYPE_ASSERT_NOT, 'verify' => static::SUBTYPE_VERIFY_NOT, 'waitFor' => static::SUBTYPE_WAIT_FOR_NOT] : ['assert' => static::SUBTYPE_ASSERT, 'verify' => static::SUBTYPE_VERIFY, 'waitFor' => static::SUBTYPE_WAIT_FOR];
             foreach ($prefix2subtype as $prefix => $subtype) {
                 // determine by prefix
                 if (Helper::hasPrefix($prefix, $methodFullName)) {
                     $resultSubtype = $subtype;
                 }
             }
             break;
     }
     if (!$resultSubtype) {
         static::throwException('Cannot evaluate subtype for method: ' . $methodFullName);
     }
     return $resultSubtype;
     // by default commands without specified prefixes is Actions
 }
 /**
  * Adds dot (if not exist) in to end of specified text (completion of sentence).
  *
  * @param string $text
  *
  * @return string   Trimmed text with dot in the end.
  */
 private function _addEndDotIfNotExist($text)
 {
     $endSymbols = '[' . join('', Helper::$endOfSentence) . ']';
     // symbol class like: [.!?]
     // find text like: "end</p>", "end </p>", "end  </p>"
     $regExpDotBeforeClosingTag = '/(?<!' . $endSymbols . '|' . $endSymbols . '\\s|' . $endSymbols . '\\s\\s)(?P<tag><\\/\\w+>)\\s*\\Z/';
     $testedText = trim(strip_tags($text));
     if ($testedText && !Helper::hasPostfix(Helper::$endOfSentence, $testedText)) {
         $postfix = preg_match($regExpDotBeforeClosingTag, $text, $m) ? $m['tag'] : '';
         $text = Helper::cutPostfix($postfix, rtrim($text)) . '.' . $postfix;
     }
     return $text;
 }