Пример #1
0
 /**
  * @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;
 }