/**
  * @return \Pharborist\Objects\ClassMethodNode
  */
 protected function addMethod(FunctionDeclarationNode $function, ClassNode $class, $alias = NULL)
 {
     $method = ClassMethodNode::fromFunction($function);
     if ($alias) {
         $method->setName($alias);
     }
     $class->appendMethod($method);
     // Add the parameters required for FormInterface conformance.
     $parameters = $method->getParameters()->toArray();
     if (empty($parameters)) {
         $parameters[0] = ParameterNode::create('$form');
         $method->appendParameter($parameters[0]);
     }
     if (sizeof($parameters) == 1) {
         $parameters[1] = ParameterNode::create('$form_state');
         $method->appendParameter($parameters[1]);
     }
     // The $form parameter must have the array type hint.
     $parameters[0]->setTypeHint('array');
     // The form state is never passed by reference.
     $parameters[1]->setReference(FALSE);
     // Additional parameters MUST have a default value of NULL in order to conform
     // to FormInterface.
     for ($i = 2; $i < sizeof($parameters); $i++) {
         $parameters[$i]->setValue(new TokenNode(T_STRING, 'NULL'));
     }
     $this->formStateRewriter->rewrite($parameters[1]);
     return $method;
 }
 /**
  * Creates a class method from this function and add it to the given
  * class definition.
  *
  * @param \Pharborist\Objects\ClassNode $class
  *  The class to add the new method to.
  *
  * @return \Pharborist\Objects\ClassMethodNode
  *  The newly created method.
  */
 public function cloneAsMethodOf(ClassNode $class)
 {
     $clone = ClassMethodNode::fromFunction($this);
     $class->appendMethod($clone);
     return $clone;
 }