Esempio n. 1
0
 /**
  * @param string|NameNode|CommaListNode|array|NULL $implements
  * @throws \InvalidArgumentException
  * @return $this
  */
 public function setImplements($implements)
 {
     if ($implements === NULL) {
         if (isset($this->implements)) {
             // Remove whitespace after implements keyword.
             $this->implements->previous()->remove();
             // Remove implements keyword
             $this->implements->previous()->remove();
             // Remove whitespace before implements keyword.
             $this->implements->previous()->remove();
             // Remove implements list.
             $this->implements->remove();
             $this->implements = NULL;
         }
     } else {
         // Type conversions.
         if (is_string($implements)) {
             $implements = NameNode::create($implements);
         }
         if ($implements instanceof NameNode) {
             $implementList = new CommaListNode();
             $implementList->append($implements);
             $implements = $implementList;
         }
         if (is_array($implements)) {
             $implementList = new CommaListNode();
             foreach ($implements as $implement) {
                 if (is_string($implement)) {
                     $implementList->appendItem(NameNode::create($implement));
                 } elseif ($implement instanceof NameNode) {
                     $implementList->appendItem($implement);
                 } else {
                     throw new \InvalidArgumentException('Invalid $implements argument');
                 }
             }
             $implements = $implementList;
         }
         // Set implements.
         if (isset($this->implements)) {
             $this->implements->replaceWith($implements);
         } else {
             $after = isset($this->extends) ? $this->extends : $this->name;
             $after->after([Token::space(), Token::_implements(), Token::space(), $implements]);
         }
         $this->implements = $implements;
     }
     return $this;
 }