yii\apidoc\models\BaseDoc::extractFirstSentence PHP Метод

extractFirstSentence() публичный статический Метод

Extracts first sentence out of text
public static extractFirstSentence ( string $text ) : string
$text string
Результат string
    public static function extractFirstSentence($text)
    {
        if (mb_strlen($text, 'utf-8') > 4 && ($pos = mb_strpos($text, '.', 4, 'utf-8')) !== false) {
            $sentence = mb_substr($text, 0, $pos + 1, 'utf-8');
            if (mb_strlen($text, 'utf-8') >= $pos + 3) {
                $abbrev = mb_substr($text, $pos - 1, 4, 'utf-8');
                if ($abbrev === 'e.g.' || $abbrev === 'i.e.') {
                    // do not break sentence after abbreviation
                    $sentence .= static::extractFirstSentence(mb_substr($text, $pos + 1, mb_strlen($text, 'utf-8'), 'utf-8'));
                }
            }
            return $sentence;
        } else {
            return $text;
        }
    }

Usage Example

Пример #1
0
 /**
  * @param \phpDocumentor\Reflection\ClassReflector\PropertyReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($reflector, $context, $config);
     if ($reflector === null) {
         return;
     }
     $this->visibility = $reflector->getVisibility();
     $this->isStatic = $reflector->isStatic();
     // bypass $reflector->getDefault() for short array syntax
     if ($reflector->getNode()->default) {
         $this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
     }
     $hasInheritdoc = false;
     foreach ($this->tags as $tag) {
         if ($tag->getName() === 'inheritdoc') {
             $hasInheritdoc = true;
         }
         if ($tag instanceof VarTag) {
             $this->type = $tag->getType();
             $this->types = $tag->getTypes();
             $this->description = ucfirst($tag->getDescription());
             $this->shortDescription = BaseDoc::extractFirstSentence($this->description);
         }
     }
     if (empty($this->shortDescription) && $context !== null && !$hasInheritdoc) {
         $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No short description for element '{$this->name}'"];
     }
 }
All Usage Examples Of yii\apidoc\models\BaseDoc::extractFirstSentence