Beispiel #1
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;
 }
 /**
  * Add property to class.
  *
  * @param string|ClassMemberListNode $property
  * @return $this
  */
 public function appendProperty($property)
 {
     if (is_string($property)) {
         $property = ClassMemberListNode::create($property);
     }
     $properties = $this->statements->children(Filter::isInstanceOf('\\Pharborist\\ClassMemberListNode'));
     if ($properties->count() === 0) {
         $this->statements->firstChild()->after($property);
     } else {
         $properties->last()->after($property);
     }
     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);
     }
 }
Beispiel #4
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;
 }
Beispiel #5
0
 /**
  * Parse a trait use statement.
  * @return TraitUseNode
  */
 private function traitUse()
 {
     $node = new TraitUseNode();
     $this->mustMatch(T_USE, $node);
     // trait_list
     $traits = new CommaListNode();
     do {
         $traits->addChild($this->name());
     } while ($this->tryMatch(',', $traits));
     $node->addChild($traits, 'traits');
     // trait_adaptations
     if ($this->tryMatch('{', $node)) {
         $adaptations = new StatementBlockNode();
         while ($this->currentType !== NULL && $this->currentType !== '}') {
             $adaptations->addChild($this->traitAdaptation());
             $this->matchHidden($adaptations);
         }
         $node->addChild($adaptations, 'adaptations');
         $this->mustMatch('}', $node, NULL, TRUE, TRUE);
         return $node;
     }
     $this->endStatement($node);
     return $node;
 }
Beispiel #6
0
 /**
  * Return mapping of class names to fully qualified names.
  *
  * @return array
  *   Associative array of namespace alias to fully qualified names.
  */
 public function getClassAliases()
 {
     return $this->body->getClassAliases();
 }