PhpParser\Node::setAttribute PHP Method

setAttribute() public method

Sets an attribute on a node.
public setAttribute ( string $key, mixed $value )
$key string
$value mixed
    public function setAttribute($key, $value);

Usage Example

 /**
  * Check all nodes
  *
  * @param  Node $node
  * @return void
  **/
 public function enterNode(Node $node)
 {
     // Skip nodes without comments.
     if (!$node->hasAttribute("comments")) {
         return;
     }
     // Check if annotations should be preserved. Only nodes with actual
     // doc comment blocks are processed.
     $comments = [];
     if ($this->preserveAnnotations) {
         $docComment = $node->getDocComment();
         if ($docComment) {
             $text = $docComment->getText();
             // Check if it is a doc comment.
             if (strpos($text, "/**") !== false) {
                 $text = $this->stripComment($text);
                 if ($text) {
                     $comments = [new Comment($text)];
                 }
             }
         }
     }
     // Remove (or set) comments.
     $node->setAttribute("comments", $comments);
     return $node;
 }
All Usage Examples Of PhpParser\Node::setAttribute