PHPStan\Type\CommentHelper::getDocComment PHP Method

getDocComment() public static method

public static getDocComment ( PhpParser\Node $node ) : string | null
$node PhpParser\Node
return string | null
    public static function getDocComment(Node $node)
    {
        $phpDoc = $node->getDocComment();
        $phpDocText = null;
        if ($phpDoc !== null) {
            return $phpDoc->getText();
        }
        $comments = $node->getAttribute('comments');
        if ($comments === null) {
            return null;
        }
        return $comments[count($comments) - 1]->getText();
    }

Usage Example

コード例 #1
0
ファイル: NodeScopeResolver.php プロジェクト: phpstan/phpstan
 private function updateScopeForVariableAssign(Scope $scope, \PhpParser\Node $node) : Scope
 {
     if ($node instanceof Assign || $node instanceof AssignRef || $node instanceof Isset_) {
         if ($node instanceof Assign || $node instanceof AssignRef) {
             $vars = [$node->var];
         } elseif ($node instanceof Isset_) {
             $vars = $node->vars;
         } else {
             throw new \PHPStan\ShouldNotHappenException();
         }
         foreach ($vars as $var) {
             $scope = $this->assignVariable($scope, $var, $node instanceof Assign || $node instanceof AssignRef ? $scope->getType($node->expr) : null);
         }
         if ($node instanceof Assign || $node instanceof AssignRef) {
             $scope = $this->lookForAssigns($scope, $node->expr);
             $comment = CommentHelper::getDocComment($node);
             if ($comment !== null && $node->var instanceof Variable && is_string($node->var->name)) {
                 $variableName = $node->var->name;
                 $processVarAnnotation = function (string $matchedType, string $matchedVariableName) use($scope, $variableName) : Scope {
                     $fileTypeMap = $this->fileTypeMapper->getTypeMap($scope->getFile());
                     if (isset($fileTypeMap[$matchedType]) && $matchedVariableName === $variableName) {
                         return $scope->assignVariable($matchedVariableName, $fileTypeMap[$matchedType]);
                     }
                     return $scope;
                 };
                 if (preg_match('#@var\\s+' . FileTypeMapper::TYPE_PATTERN . '\\s+\\$([a-zA-Z0-9_]+)#', $comment, $matches)) {
                     $scope = $processVarAnnotation($matches[1], $matches[2]);
                 } elseif (preg_match('#@var\\s+\\$([a-zA-Z0-9_]+)\\s+' . FileTypeMapper::TYPE_PATTERN . '#', $comment, $matches)) {
                     $scope = $processVarAnnotation($matches[2], $matches[1]);
                 }
             }
         }
         if ($node instanceof Isset_) {
             foreach ($vars as $var) {
                 if ($var instanceof PropertyFetch) {
                     $scope = $scope->specifyFetchedPropertyFromIsset($var);
                 }
             }
         }
     }
     return $scope;
 }
All Usage Examples Of PHPStan\Type\CommentHelper::getDocComment
CommentHelper