コード例 #1
0
ファイル: InterfaceNode.php プロジェクト: kidaa30/redcat
 /**
  * @param string|\Pharborist\Namespaces\NameNode $extends
  * @return $this
  */
 public function setExtends($extends)
 {
     if ($extends === NULL) {
         if (isset($this->extends)) {
             // Remove whitespace after extends keyword.
             $this->extends->previous()->remove();
             // Remove extends keyword.
             $this->extends->previous()->remove();
             // Remove whitespace before extends keyword.
             $this->extends->previous()->remove();
             // Remove extends namespace.
             $this->extends->remove();
             $this->extends = NULL;
         }
     } else {
         if (!is_array($extends)) {
             $extends = [$extends];
         }
         $extendsList = new CommaListNode();
         foreach ($extends as $extend) {
             if (is_string($extend)) {
                 $extendsList->appendItem(NameNode::create($extend));
             } elseif ($extend instanceof NameNode) {
                 $extendsList->appendItem($extend);
             } else {
                 throw new \InvalidArgumentException('Invalid $extends argument');
             }
         }
         $extends = $extendsList;
         if (isset($this->extends)) {
             $this->extends->replaceWith($extends);
         } else {
             $this->name->after([Token::space(), Token::_extends(), Token::space(), $extends]);
         }
         $this->extends = $extends;
     }
     return $this;
 }
コード例 #2
0
ファイル: ClassNode.php プロジェクト: kidaa30/redcat
 /**
  * @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;
 }