Example #1
0
 /**
  * Remove the visibility modifier.
  */
 protected function removeVisibility()
 {
     // Remove whitespace after visibility keyword.
     $this->visibility->next()->remove();
     // Remove visibility keyword.
     $this->visibility->remove();
 }
Example #2
0
 /**
  * @param boolean $is_reference
  * @return $this
  */
 public function setReference($is_reference)
 {
     if ($is_reference) {
         if (!isset($this->reference)) {
             /** @var \Pharborist\Functions\FunctionDeclarationNode|\Pharborist\Objects\ClassMethodNode|\Pharborist\Objects\InterfaceMethodNode $this */
             $this->reference = Token::reference();
             $this->name->before($this->reference);
         }
     } else {
         if (isset($this->reference)) {
             $this->reference->remove();
         }
     }
     return $this;
 }
Example #3
0
 public function clearLexicalVariables()
 {
     if ($this->hasLexicalVariables()) {
         $this->lexicalUse->nextUntil(Filter::is($this->body))->remove();
         $this->lexicalUse->remove();
     }
 }
Example #4
0
 /**
  * @param boolean $is_static
  *
  * @return $this
  */
 public function setStatic($is_static)
 {
     if ($is_static) {
         if (!isset($this->static)) {
             $this->static = Token::_static();
             $this->visibility->after([Token::space(), $this->static]);
         }
     } else {
         if (isset($this->static)) {
             // Remove whitespace after static keyword.
             $this->static->next()->remove();
             // Remove static keyword.
             $this->static->remove();
         }
     }
     return $this;
 }
Example #5
0
 /**
  * @param boolean $is_static
  * @return $this
  */
 public function setStatic($is_static)
 {
     if ($is_static) {
         if (!isset($this->static)) {
             // Insert before T_FUNCTION.
             $function_token = $this->name->previous()->previous();
             $this->static = Token::_static();
             $function_token->before([$this->static, Token::space()]);
         }
     } else {
         if (isset($this->static)) {
             // Remove whitespace after static keyword.
             $this->static->next()->remove();
             // Remove static keyword.
             $this->static->remove();
         }
     }
     return $this;
 }
Example #6
0
 /**
  * @param boolean $is_variadic
  * @return $this
  */
 public function setVariadic($is_variadic)
 {
     if ($is_variadic) {
         if (!isset($this->variadic)) {
             $this->variadic = Token::splat();
             $this->name->before($this->variadic);
         }
     } else {
         if (isset($this->variadic)) {
             $this->variadic->remove();
         }
     }
 }
Example #7
0
 /**
  * @param boolean $is_final
  * @return $this
  */
 public function setFinal($is_final)
 {
     if ($is_final) {
         if (!isset($this->final)) {
             $this->final = Token::_final();
             $this->prepend([$this->final, Token::space()]);
             $this->setAbstract(FALSE);
         }
     } else {
         if (isset($this->final)) {
             // Remove whitespace.
             $this->final->next()->remove();
             // Remove final.
             $this->final->remove();
         }
     }
     return $this;
 }
Example #8
0
 /**
  * Sets the imported item's alias. If NULL is passed, the alias is removed.
  *
  * @param \Pharborist\TokenNode|string|NULL $alias
  *
  * @return $this
  */
 public function setAlias($alias)
 {
     if (is_string($alias)) {
         $alias = new TokenNode(T_STRING, $alias);
     }
     if ($alias instanceof TokenNode) {
         if ($this->hasAlias()) {
             $this->alias->replaceWith($alias);
         } else {
             $this->alias = $alias;
             $this->addChild(WhitespaceNode::create(' '));
             $this->addChild(Token::_as());
             $this->addChild(WhitespaceNode::create(' '));
             $this->addChild($alias, 'alias');
         }
     } elseif ($alias === NULL && $this->hasAlias()) {
         $this->alias->previousUntil(Filter::isInstanceOf('\\Pharborist\\Namespaces\\NameNode'))->remove();
         $this->alias->remove();
         $this->alias = NULL;
     } else {
         throw new \InvalidArgumentException();
     }
     return $this;
 }