Beispiel #1
0
 /**
  * Wrap single line body statements in braces.
  *
  * @param Node|NULL $node
  */
 protected function encloseBlock($node)
 {
     if ($node && !$node instanceof StatementBlockNode) {
         $blockNode = new StatementBlockNode();
         $blockNode->append([Token::openBrace(), clone $node, Token::closeBrace()]);
         $node->replaceWith($blockNode);
     }
 }
Beispiel #2
0
 /**
  * @param boolean $is_abstract
  * @return $this
  */
 public function setAbstract($is_abstract)
 {
     if ($is_abstract) {
         if (!isset($this->abstract)) {
             $this->abstract = Token::_abstract();
             $this->prepend([$this->abstract, Token::space()]);
             $this->setFinal(FALSE);
             // Remove method body since abstract method doesn't have one.
             $this->getBody()->previous(Filter::isInstanceOf('\\Pharborist\\WhitespaceNode'))->remove();
             $this->getBody()->replaceWith(Token::semiColon());
             $this->body = NULL;
         }
     } else {
         if (isset($this->abstract)) {
             // Remove whitespace.
             $this->abstract->next()->remove();
             // Remove abstract.
             $this->abstract->remove();
             // Add empty body.
             $body = new StatementBlockNode();
             $body->append([Token::openBrace(), Token::closeBrace()]);
             $this->lastChild()->replaceWith($body);
             $this->lastChild()->before(Token::space());
             $this->body = $body;
         }
     }
     return $this;
 }