/** * @param string|NameNode|TokenNode $type_hint * @return $this */ public function setTypeHint($type_hint) { if (is_string($type_hint)) { $type = $type_hint; switch ($type) { case 'array': $type_hint = Token::_array(); break; case 'callable': $type_hint = Token::_callable(); break; default: $type_hint = NameNode::create($type); break; } } if ($type_hint) { if (isset($this->typeHint)) { $this->typeHint->replaceWith($type_hint); } else { $this->typeHint = $type_hint; $this->prepend([$this->typeHint, Token::space()]); } } else { $this->typeHint->remove(); } return $this; }
/** * @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_string($extends)) { $extends = NameNode::create($extends); } if (isset($this->extends)) { $this->extends->replaceWith($extends); } else { $this->name->after([Token::space(), Token::_extends(), Token::space(), $extends]); } $this->extends = $extends; } return $this; }