public function testMatchReflector()
 {
     $function = FunctionDeclarationNode::create('array_walk');
     $reflector = new \ReflectionFunction('array_walk');
     // $function->getReference() should return a TokenNode or NULL, which will
     // loosely evaluate to TRUE or FALSE
     $this->assertEquals($function->getReference(), $reflector->returnsReference());
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $this->moduleHandler->loadInclude($this->configuration['module'], 'php', 'api');
     $hook = $this->configuration['hook'];
     $function = FunctionDeclarationNode::create($this->target->id() . '_' . $hook);
     $function->setDocComment(DocCommentNode::create('Implements hook_' . $hook));
     $reflector = new \ReflectionFunction('hook_' . $hook);
     $function->matchReflector($reflector);
     $module = $this->target->getPath('.module');
     $doc = $this->target->open($module)->append($function);
     $this->target->save($doc);
 }
 public function testFunctionDeclaration()
 {
     $expected = 'function test($a, $b) {}';
     $function = FunctionDeclarationNode::create('test', ['$a', '$b']);
     $this->assertEquals($expected, $function->getText());
     $function = FunctionDeclarationNode::create('badoink');
     $function->appendParameter(ParameterNode::create('badonk'));
     $this->assertEquals('function badoink($badonk) {}', $function->getText());
 }
 /**
  * Creates an empty implementation of a hook.
  *
  * @param TargetInterface $target
  *  The target module.
  * @param string $hook
  *  The hook to implement, without the hook_ prefix.
  *
  * @return \Pharborist\Functions\FunctionDeclarationNode
  *  The hook implementation, appended to the main module file.
  */
 protected function implement(TargetInterface $target, $hook)
 {
     $function = FunctionDeclarationNode::create($target->id() . '_' . $hook);
     $function->setDocComment(DocCommentNode::create('Implements hook_' . $hook . '().'));
     $module_file = $target->getPath('.module');
     $target->open($module_file)->append($function);
     WhitespaceNode::create("\n")->insertBefore($function);
     WhitespaceNode::create("\n")->insertAfter($function);
     return $function;
 }