/**
  * {@inheritdoc}
  */
 public function add(NodeInterface $node)
 {
     /** @var \Pharborist\Functions\FunctionDeclarationNode|\Pharborist\Functions\FunctionCallNode $node */
     $fields = ['id' => (string) $node->getName(), 'file' => $node->getFilename(), 'type' => get_class($node)];
     if ($node instanceof FunctionDeclarationNode) {
         $logical = new ContainsLogicFilter();
         $logical->whitelist('t');
         $logical->whitelist('drupal_get_path');
         $fields['has_logic'] = (int) $node->is($logical);
     }
     $this->db->insert($this->table)->fields($fields)->execute();
 }
 /**
  * Executes the target module's implementation of the specified hook, and
  * returns the result.
  *
  * @return mixed
  *
  * @throws \LogicException if the target module doesn't implement the
  * specified hook, or if the implementation contains logic.
  *
  * @deprecated
  */
 protected function executeHook(TargetInterface $target, $hook)
 {
     $indexer = $target->getIndexer('function');
     if ($indexer->has($hook)) {
         // Configure the ContainsLogicFilter so that certain "safe" functions
         // will pass it.
         $has_logic = new ContainsLogicFilter();
         $has_logic->whitelist('t');
         $has_logic->whitelist('drupal_get_path');
         $function = $indexer->get($hook);
         if ($function->is($has_logic)) {
             throw new \LogicException('{target}_{hook} cannot be executed because it contains logic.');
         } else {
             $function_name = $function->getName()->getText();
             if (!function_exists($function_name)) {
                 eval($function->getText());
             }
             return call_user_func($function_name);
         }
     } else {
         throw new \LogicException('{target} does not implement hook_{hook}.');
     }
 }
 public function testWhiteListedFunctionCallIsNotLogic()
 {
     $this->filter->whitelist('bar');
     $this->assertFalse(Parser::parseSnippet('function foo() { bar(); }')->is($this->filter));
 }