Beispiel #1
0
 /**
  * Appends a parameter.
  *
  * @param \Pharborist\Functions\ParameterNode|callable $parameter
  *  Either an existing parameter node, or a callable which will return
  *  the parameter to append. The callable will receive $this as its
  *  only argument.
  *
  * @return $this
  *
  * @throws \InvalidArgumentException
  */
 public function appendParameter($parameter)
 {
     if (is_callable($parameter)) {
         $parameter = $parameter($this);
     }
     if (!$parameter instanceof ParameterNode) {
         throw new \InvalidArgumentException();
     }
     $this->parameters->appendItem($parameter);
     return $this;
 }
Beispiel #2
0
 /**
  * @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;
 }
 /**
  * @param LexicalVariableNode $variable
  */
 public function appendLexicalVariable(LexicalVariableNode $variable)
 {
     $this->createLexicalVariables();
     $this->lexicalVariables->appendItem($variable);
 }
Beispiel #4
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;
 }