Overview

Namespaces

  • Pharborist
    • Constants
    • ControlStructures
    • Exceptions
    • Functions
    • Generators
    • Namespaces
    • Objects
    • Operators
    • Types
    • Variables

Classes

  • Pharborist\Variables\CompoundVariableNode
  • Pharborist\Variables\GlobalStatementNode
  • Pharborist\Variables\ReferenceVariableNode
  • Pharborist\Variables\StaticVariableNode
  • Pharborist\Variables\StaticVariableStatementNode
  • Pharborist\Variables\VariableNode
  • Pharborist\Variables\VariableVariableNode

Interfaces

  • Pharborist\Variables\VariableExpressionNode
  • Overview
  • Namespace
  • Class
  1: <?php
  2: namespace Pharborist;
  3: 
  4: /**
  5:  * A block of line comments, e.g.:
  6:  * ```
  7:  * // This is a haiku.
  8:  * // Seriously, it is one.
  9:  * // Isn't that awesome?
 10:  * ```
 11:  */
 12: class LineCommentBlockNode extends ParentNode {
 13:   use UncommentTrait;
 14: 
 15:   /**
 16:    * Create line comment block.
 17:    *
 18:    * @param string $comment
 19:    *   Comment without leading prefix.
 20:    *
 21:    * @return LineCommentBlockNode
 22:    */
 23:   public static function create($comment) {
 24:     $block_comment = new LineCommentBlockNode();
 25:     $comment = trim($comment);
 26:     $lines = array_map('rtrim', explode("\n", $comment));
 27:     foreach ($lines as $line) {
 28:       $comment_node = new CommentNode(T_COMMENT, '// ' . $line . "\n");
 29:       $block_comment->addChild($comment_node);
 30:     }
 31:     return $block_comment;
 32:   }
 33: 
 34:   /**
 35:    * @return string
 36:    */
 37:   public function getCommentText() {
 38:     $comment = '';
 39:     $child = $this->firstChild();
 40:     $first = TRUE;
 41:     while ($child) {
 42:       if ($child instanceof CommentNode) {
 43:         if ($first) {
 44:           $first = FALSE;
 45:         }
 46:         else {
 47:           $comment .= "\n";
 48:         }
 49:         $comment .= $child->getCommentText();
 50:       }
 51:       $child = $child->next;
 52:     }
 53:     return $comment;
 54:   }
 55: 
 56:   /**
 57:    * Set indent for document comment.
 58:    *
 59:    * @param string $indent
 60:    *   Whitespace to use as indent.
 61:    * @return $this
 62:    */
 63:   public function setIndent($indent) {
 64:     // Normalize comment block.
 65:     $this->removeIndent();
 66:     // Add indent to comment block.
 67:     $this->addIndent($indent);
 68:     return $this;
 69:   }
 70: 
 71:   /**
 72:    * Remove indent from document comment.
 73:    *
 74:    * @return $this
 75:    */
 76:   public function removeIndent() {
 77:     $this->children(function (Node $node) {
 78:       return !($node instanceof CommentNode);
 79:     })->remove();
 80:     return $this;
 81:   }
 82: 
 83:   /**
 84:    * Add indent to comment.
 85:    *
 86:    * @param string $whitespace
 87:    *   Additional whitespace to add.
 88:    * @return $this
 89:    */
 90:   public function addIndent($whitespace) {
 91:     $has_indent = $this->children(function (Node $node) {
 92:       return !($node instanceof CommentNode);
 93:     })->count() > 0;
 94:     if ($has_indent) {
 95:       $this->children(Filter::isInstanceOf('\Pharborist\WhitespaceNode'))->each(function (WhitespaceNode $ws_node) use ($whitespace) {
 96:         $ws_node->setText($ws_node->getText() . $whitespace);
 97:       });
 98:     }
 99:     else {
100:       $this->children()->before(Token::whitespace($whitespace));
101:     }
102:     return $this;
103:   }
104: }
105: 
Pharborist API documentation generated by ApiGen