Get the @var of a doc comment.

@param string $docComment cannot type-hint, if empty getDocComment() returns false even though it says string
@return string
351067
public function getVar($docComment): string
    {
        preg_match(self::REGEX_VAR_PATTERN, (string) $docComment, $matches);

        if ($matches) {
            return $matches[1];
        }

        return '';
    }
661030
function captureJsDoc(comments) {
  let doc

  // capture XSDoc
  comments.forEach(comment => {
    // skip non-block comments
    if (comment.type !== 'Block') return
    try {
      doc = doctrine.parse(comment.value, { unwrap: true })
    } catch (err) {
      /* don't care, for now? maybe add to `errors?` */
    }
  })

  return doc
}
684829
public function GetOffset($Comment) {
      $this->FireEvent('BeforeGetOffset');
      
      if (is_numeric($Comment)) {
         $Comment = $this->GetID($Comment);
      }

      $this->SQL
         ->Select('c.CommentID', 'count', 'CountComments')
         ->From('Comment c')
         ->Where('c.DiscussionID', GetValue('DiscussionID', $Comment));

      $this->SQL->BeginWhereGroup();

      // Figure out the where clause based on the sort.
      foreach ($this->_OrderBy as $Part) {
         //$Op = count($this->_OrderBy) == 1 || isset($PrevWhere) ? '=' : '';
         list($Expr, $Value) = $this->_WhereFromOrderBy($Part, $Comment, '');

         if (!isset($PrevWhere)) {
            $this->SQL->Where($Expr, $Value);
         } else {
            $this->SQL->BeginWhereGroup();
            $this->SQL->OrWhere($PrevWhere[0], $PrevWhere[1]);
            $this->SQL->Where($Expr, $Value);
            $this->SQL->EndWhereGroup();
         }

         $PrevWhere = $this->_WhereFromOrderBy($Part, $Comment, '==');
      }

      $this->SQL->EndWhereGroup();

      return $this->SQL
         ->Get()
         ->FirstRow()
         ->CountComments;
   }
35848
public function getComment($pCellCoordinate = 'A1')
    {
        // Uppercase coordinate
        $pCellCoordinate = strtoupper($pCellCoordinate);

        if (strpos($pCellCoordinate, ':') !== false || strpos($pCellCoordinate, ',') !== false) {
            throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.');
        } elseif (strpos($pCellCoordinate, '$') !== false) {
            throw new PHPExcel_Exception('Cell coordinate string must not be absolute.');
        } elseif ($pCellCoordinate == '') {
            throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.');
        } else {
            // Check if we already have a comment for this cell.
            // If not, create a new comment.
            if (isset($this->comments[$pCellCoordinate])) {
                return $this->comments[$pCellCoordinate];
            } else {
                $newComment = new PHPExcel_Comment();
                $this->comments[$pCellCoordinate] = $newComment;
                return $newComment;
            }
        }
    }
524995
private function getCommentDescription($docComment)
    {
        $lines = explode(PHP_EOL, $docComment);

        $descriptionLines = [];

        foreach ($lines as $line) {
            if (false === strpos($line, '@')) {
                $descriptionLines[] = $line;
            }
        }

        return $this->transformDescriptionLines($descriptionLines);
    }
1277091
public static function extractReflectionVisibility($docComments)
    {
        preg_match('/@visible\ (.*)(\n|\r)/i', $docComments, $visible);
        return !(array_key_exists(1, $visible) && false !== strpos($visible[1], 'false'));
    }
1165570
protected function getDocCommentParser()
    {
        if (!is_object($this->docCommentParser)) {
            $this->docCommentParser = new DocCommentParser;
            $this->docCommentParser->parseDocComment($this->getDocComment());
        }
        return $this->docCommentParser;
    }
311561
protected function getComment($asPhpComment = true)
    {
        $comment = $this->parameters->get('comment');
        // strip hints for mysql-exporter in comments (starting with {d:keyword}
        // or {doctrine:keyword} and ending with {/d:keyword}
        if ($comment = trim(preg_replace(sprintf('/\{(%s):([^\}]+)\}(.+?)\{\/\1:\2\}/si', $this->getFormatter()->getCommentTagPrefix()), '', $comment))) {
            if ($asPhpComment) {
                $comment = implode("\n", Comment::wrap($comment."\n", ' * %s'));
            }

            return $comment;
        }
    }
921033
public function getComment()
    {
        if (!$this->_commentFetched) {
            $this->_comment = $this->_fetchComment();
            $this->_commentFetched = true;
        }
        return $this->_comment;
    }
631776
static private function getKeysAndValues($docCommentLine){
        
        if(strpos($docCommentLine,"@") === FALSE){
            throw new \Exception('Parse Error');
        }
        
        $posAmp = strpos($docCommentLine, '@');
        $strBeforeAmp = substr($docCommentLine, 0, $posAmp);
        if(trim($strBeforeAmp) != "*") throw new \Exception('Parse Error');
        
        $docCommentLine = substr($docCommentLine, $posAmp+1);
        
        $posFirstSpace = strpos($docCommentLine, ' ');
        $keyStr = $posFirstSpace !== FALSE ? substr($docCommentLine, 0, $posFirstSpace) : $docCommentLine;
        
        if(trim($keyStr) == '') throw new \Exception('Parse Error');
        
        if(strpos($keyStr, '(') !== FALSE) throw new \Exception('Parse Error');
        
        $keys = preg_split('/\./', trim($keyStr));
        
        $valueStr = trim(substr($docCommentLine, strlen($keyStr)));
        
        if(strlen($valueStr) == 0){
            // default value is true
            $valueStr = "true";
        }
        
        $valueIsInBracket = false;
        if(strpos($valueStr, '(') === 0){
            $valueIsInBracket = true;
            $valueStr = substr($valueStr, 1);
        }
        
        $values = [];
        $valueChars = str_split($valueStr);
        $valueStrLength = strlen($valueStr);
        $charStack = [];
        $stringInQuotes = false;
        $escapedChar = false;
        for($i = 0; $i < $valueStrLength; $i++){
            $char = $valueChars[$i];
            
            if($stringInQuotes){
                if($escapedChar){
                    $charStack[] = $char;
                    $escapedChar = false;
                }else if ($char == '"'){
                    // end the string
                    $values[] = join('', $charStack);
                    $charStack = [];
                    $stringInQuotes = false;
                }else if ($char ==  '\\'){
                    $escapedChar = true;
                }else{
                    $charStack[] = $char;
                }
            }else if ($char ==  '"'){
                if(count($charStack) > 0) throw new \Exception('Parse Error');
                $stringInQuotes = true;
            }else if ($char == ',' || $char == ' '){
                if(count($charStack) > 0){
                    $values[] = join('', $charStack);
                    $charStack = [];
                }
            }else if ($valueIsInBracket && $char == ')'){
                if(count($charStack) > 0){
                    $values[] = join('', $charStack);
                    $charStack = [];
                    break;
                }
            }else{
                $charStack[] = $char;
            }
        }
        if(count($charStack) > 0){
            $values[] = join('', $charStack);
            $charStack = [];
        }
        
        foreach ($values as $i => $value){
            if(is_numeric($value)){
                $values[$i] = 0 + $value;
            }
            
            if(is_string($value) && strtoupper($value) == "TRUE"){
                $values[$i] = true;
            }
            
            if(is_string($value) && strtoupper($value) == "FALSE"){
                $values[$i] = false;
            }
        }
        
        if(!$valueIsInBracket && count($values) ==  1){
            $values = $values[0];
        }
        
        return [
            "keys" => $keys,
            "values" => $values
        ];
        
    }
414424
public function comment($comment = null) {
		if ($comment) {
			$this->_config['comment'] = $comment;
			return $this;
		}
		return $this->_config['comment'];
	}
1294960
public String getJsDoc() {
        Comment comment = getJsDocNode();
        if (comment != null) {
          return comment.getValue();
        }
        return null;
    }
780692
final protected function parseDocComment($docComment, $docType = '') {
        if (empty($docComment) || !is_string($docComment))
            return array();

        $annotations = array();
        $match = '#@' . stripslashes($docType) . '(.*?)\n#s';
        preg_match_all($match, $docComment, $annotations);
        return $annotations[1];
    }
810964
protected function getDocCommentPos(): ?int
    {
        if ($this->docCommentPos === -1) {
            $this->docCommentPos = $this->loadDocCommentPos();
        }

        return $this->docCommentPos;
    }
1153400
public function setComment($comment): self
    {
        if (!empty($comment)) {
            if (is_array($comment)) {
                $this->docComment->setLines($comment);
            } elseif (is_string($comment)) {
                $this->docComment->setString($comment);
            }
        }

        return $this;
    }
1328333
public static function extractFunctionDocblockInfo($comment, $line_number)
    {
        $comments = DocComment::parse($comment, $line_number);

        $info = new FunctionDocblockComment();

        if (isset($comments['specials']['return']) || isset($comments['specials']['psalm-return'])) {
            /** @var array<int, string> */
            $return_specials = isset($comments['specials']['psalm-return'])
                ? $comments['specials']['psalm-return']
                : $comments['specials']['return'];

            self::extractReturnType((string) reset($return_specials), array_keys($return_specials)[0], $info);
        }

        if (isset($comments['specials']['param']) || isset($comments['specials']['psalm-param'])) {
            $all_params = (isset($comments['specials']['param']) ? $comments['specials']['param'] : [])
                + (isset($comments['specials']['psalm-param']) ? $comments['specials']['psalm-param'] : []);

            /** @var string $param */
            foreach ($all_params as $line_number => $param) {
                $line_parts = self::splitDocLine($param);

                if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') {
                    continue;
                }

                if (count($line_parts) > 1) {
                    if (!preg_match('/\[[^\]]+\]/', $line_parts[0])
                        && preg_match('/^&?(\.\.\.)?&?\$[A-Za-z0-9_]+,?$/', $line_parts[1])
                        && $line_parts[0][0] !== '{'
                    ) {
                        $line_parts[1] = str_replace('&', '', $line_parts[1]);

                        if ($line_parts[0][0] === '$' && !preg_match('/^\$this(\||$)/', $line_parts[0])) {
                            throw new IncorrectDocblockException('Misplaced variable');
                        }

                        $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]);

                        $info->params[] = [
                            'name' => $line_parts[1],
                            'type' => $line_parts[0],
                            'line_number' => (int)$line_number,
                        ];
                    }
                } else {
                    throw new DocblockParseException('Badly-formatted @param');
                }
            }
        }

        if (isset($comments['specials']['param-out'])) {
            /** @var string $param */
            foreach ($comments['specials']['param-out'] as $line_number => $param) {
                $line_parts = self::splitDocLine($param);

                if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') {
                    continue;
                }

                if (count($line_parts) > 1) {
                    if (!preg_match('/\[[^\]]+\]/', $line_parts[0])
                        && preg_match('/^(\.\.\.)?&?\$[A-Za-z0-9_]+,?$/', $line_parts[1])
                        && $line_parts[0][0] !== '{'
                    ) {
                        if ($line_parts[1][0] === '&') {
                            $line_parts[1] = substr($line_parts[1], 1);
                        }

                        if ($line_parts[0][0] === '$' && !preg_match('/^\$this(\||$)/', $line_parts[0])) {
                            throw new IncorrectDocblockException('Misplaced variable');
                        }

                        $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]);

                        $info->params_out[] = [
                            'name' => $line_parts[1],
                            'type' => $line_parts[0],
                            'line_number' => (int)$line_number,
                        ];
                    }
                } else {
                    throw new DocblockParseException('Badly-formatted @param');
                }
            }
        }

        if (isset($comments['specials']['global'])) {
            foreach ($comments['specials']['global'] as $line_number => $global) {
                $line_parts = self::splitDocLine($global);

                if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') {
                    continue;
                }

                if (count($line_parts) > 1) {
                    if (!preg_match('/\[[^\]]+\]/', $line_parts[0])
                        && preg_match('/^(\.\.\.)?&?\$[A-Za-z0-9_]+,?$/', $line_parts[1])
                        && $line_parts[0][0] !== '{'
                    ) {
                        if ($line_parts[1][0] === '&') {
                            $line_parts[1] = substr($line_parts[1], 1);
                        }

                        if ($line_parts[0][0] === '$' && !preg_match('/^\$this(\||$)/', $line_parts[0])) {
                            throw new IncorrectDocblockException('Misplaced variable');
                        }

                        $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]);

                        $info->globals[] = [
                            'name' => $line_parts[1],
                            'type' => $line_parts[0],
                            'line_number' => (int)$line_number,
                        ];
                    }
                } else {
                    throw new DocblockParseException('Badly-formatted @param');
                }
            }
        }

        if (isset($comments['specials']['deprecated'])) {
            $info->deprecated = true;
        }

        if (isset($comments['specials']['internal'])) {
            $info->internal = true;
        }

        if (isset($comments['specials']['psalm-suppress'])) {
            foreach ($comments['specials']['psalm-suppress'] as $suppress_entry) {
                $info->suppress[] = preg_split('/[\s]+/', $suppress_entry)[0];
            }
        }

        if (isset($comments['specials']['throws'])) {
            foreach ($comments['specials']['throws'] as $throws_entry) {
                $throws_class = preg_split('/[\s]+/', $throws_entry)[0];

                if (!$throws_class) {
                    throw new IncorrectDocblockException('Unexpectedly empty @throws');
                }

                $info->throws[] = $throws_class;
            }
        }

        if (strpos(strtolower($comments['description']), '@inheritdoc') !== false
            || isset($comments['specials']['inheritdoc']) || isset($comments['specials']['inheritDoc'])) {
            $info->inheritdoc = true;
        }

        if (isset($comments['specials']['template']) || isset($comments['specials']['psalm-template'])) {
            $all_templates = (isset($comments['specials']['template']) ? $comments['specials']['template'] : [])
                + (isset($comments['specials']['psalm-template']) ? $comments['specials']['psalm-template'] : []);

            foreach ($all_templates as $template_line) {
                $template_type = preg_split('/[\s]+/', $template_line);

                if (count($template_type) > 2
                    && in_array(strtolower($template_type[1]), ['as', 'super', 'of'], true)
                ) {
                    $info->templates[] = [
                        $template_type[0],
                        strtolower($template_type[1]), $template_type[2]
                    ];
                } else {
                    $info->templates[] = [$template_type[0]];
                }
            }
        }

        if (isset($comments['specials']['template-typeof'])) {
            foreach ($comments['specials']['template-typeof'] as $template_typeof) {
                $typeof_parts = preg_split('/[\s]+/', $template_typeof);

                if (count($typeof_parts) < 2 || $typeof_parts[1][0] !== '$') {
                    throw new IncorrectDocblockException('Misplaced variable');
                }

                $info->template_typeofs[] = [
                    'template_type' => $typeof_parts[0],
                    'param_name' => substr($typeof_parts[1], 1),
                ];
            }
        }

        if (isset($comments['specials']['psalm-assert'])) {
            foreach ($comments['specials']['psalm-assert'] as $assertion) {
                $assertion_parts = preg_split('/[\s]+/', $assertion);

                if (count($assertion_parts) < 2 || $assertion_parts[1][0] !== '$') {
                    throw new IncorrectDocblockException('Misplaced variable');
                }

                $info->assertions[] = [
                    'type' => $assertion_parts[0],
                    'param_name' => substr($assertion_parts[1], 1),
                ];
            }
        }

        if (isset($comments['specials']['psalm-assert-if-true'])) {
            foreach ($comments['specials']['psalm-assert-if-true'] as $assertion) {
                $assertion_parts = preg_split('/[\s]+/', $assertion);

                if (count($assertion_parts) < 2 || $assertion_parts[1][0] !== '$') {
                    throw new IncorrectDocblockException('Misplaced variable');
                }

                $info->if_true_assertions[] = [
                    'type' => $assertion_parts[0],
                    'param_name' => substr($assertion_parts[1], 1),
                ];
            }
        }

        if (isset($comments['specials']['psalm-assert-if-false'])) {
            foreach ($comments['specials']['psalm-assert-if-false'] as $assertion) {
                $assertion_parts = preg_split('/[\s]+/', $assertion);

                if (count($assertion_parts) < 2 || $assertion_parts[1][0] !== '$') {
                    throw new IncorrectDocblockException('Misplaced variable');
                }

                $info->if_false_assertions[] = [
                    'type' => $assertion_parts[0],
                    'param_name' => substr($assertion_parts[1], 1),
                ];
            }
        }

        $info->variadic = isset($comments['specials']['psalm-variadic']);
        $info->ignore_nullable_return = isset($comments['specials']['psalm-ignore-nullable-return']);
        $info->ignore_falsable_return = isset($comments['specials']['psalm-ignore-falsable-return']);

        return $info;
    }
713738
public static String getTextFromComment(Comment comment) {
    switch (comment.getStyle()) {
      case BLOCK:
        return comment.getText().replaceAll("^\\s*/\\*\\s*(.*?)\\s*\\*/\\s*", "$1");
      case LINE:
        return comment.getText().replaceAll("^\\s*//\\s*", "");
      default:
        return comment.getText();
    }
  }