/**
  * Adds a method to a class/trait.
  *
  * @param \Pharborist\Functions\FunctionDeclarationNode|\Pharborist\Objects\ClassMethodNode|string $method
  *  The method to append. Can either be an existing method, a function (which
  *  will be converted to a public method), or a string (a new public method
  *  will be created with that name).
  *
  * @return $this
  */
 public function appendMethod($method)
 {
     if ($method instanceof FunctionDeclarationNode) {
         $method = ClassMethodNode::fromFunction($method);
     } elseif (is_string($method)) {
         $method = ClassMethodNode::create($method);
     }
     $this->statements->lastChild()->before($method);
     FormatterFactory::format($this);
     return $this;
 }
Beispiel #2
0
 /**
  * Adds a method to interface.
  *
  * @param InterfaceMethodNode|string $method
  *   The method to append. Can either be an existing method, or a string (a
  *   new public method will be created with that name).
  *
  * @return $this
  */
 public function appendMethod($method)
 {
     if (is_string($method)) {
         $method = InterfaceMethodNode::create($method);
     }
     $this->statements->lastChild()->before($method);
     FormatterFactory::format($this);
     return $this;
 }
Beispiel #3
0
 public function endStatementBlockNode(StatementBlockNode $node)
 {
     $nested = $this->nodeData[$node];
     unset($this->nodeData[$node]);
     if ($nested) {
         $this->indentLevel--;
     }
     $last = $node->lastChild();
     if ($last instanceof TokenNode && $last->getType() === '}') {
         $this->newlineBefore($last, TRUE);
     }
 }