Exemplo n.º 1
0
 /**
  * Utility method to PSR4-ify a class. It'll move the class into its own file
  * in the given module's namespace. The class is modified in-place, so you
  * should clone it before calling this function if you want to make a PSR-4
  * *copy* of it.
  *
  * @param \Drupal\drupalmoduleupgrader\TargetInterface $target
  *  The module which will own the class.
  * @param \Pharborist\ClassNode $class
  *  The class to modify.
  *
  * @return \Pharborist\ClassNode
  *  The modified class, returned for convenience.
  */
 public static function toPSR4(TargetInterface $target, ClassNode $class)
 {
     $ns = 'Drupal\\' . $target->id();
     RootNode::create($ns)->getNamespace($ns)->append($class->remove());
     WhitespaceNode::create("\n\n")->insertBefore($class);
     return $class;
 }
Exemplo n.º 2
0
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        $unit_tests = [];
        $test_files = $target->getIndexer('class')->getQuery(['file'])->condition('parent', 'DrupalUnitTestCase')->execute()->fetchCol();
        foreach ($test_files as $test_file) {
            /** @var \Pharborist\Objects\Classnode[] $tests */
            $tests = $target->open($test_file)->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))->toArray();
            foreach ($tests as $test) {
                if ((string) $test->getExtends() === 'DrupalUnitTestCase') {
                    $unit_tests[] = $test;
                }
            }
        }
        /** @var \Pharborist\Objects\ClassNode $unit_test */
        foreach ($unit_tests as $unit_test) {
            $unit_test->setExtends('\\Drupal\\Tests\\UnitTestCase');
            $comment_text = <<<END
@FIXME
Unit tests are now written for the PHPUnit framework. You will need to refactor
this test in order for it to work properly.
END;
            $comment = DocCommentNode::create($comment_text);
            $unit_test->setDocComment($comment);
            $ns = 'Drupal\\Tests\\' . $target->id() . '\\Unit';
            $doc = RootNode::create($ns)->getNamespace($ns)->append($unit_test->remove());
            WhitespaceNode::create("\n\n")->insertBefore($unit_test);
            $this->write($target, 'tests/src/Unit/' . $unit_test->getName() . '.php', "<?php\n\n{$doc}");
        }
    }
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
        $function = $target->getIndexer('function')->get('hook_user_login');
        // The $edit parameter is defunct in Drupal 8, but we'll leave it in
        // there as an empty array to prevent errors, and move it to the back
        // of the line.
        /** @var \Pharborist\Functions\ParameterNode $edit */
        $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(ArrayNode::create([]));
        $function->appendParameter($edit);
        // Slap a FIXME on the hook implementation, informing the developer that
        // $edit and $category are dead.
        $comment = $function->getDocComment();
        $comment_text = $comment ? $comment->getCommentText() : '';
        if ($comment_text) {
            $comment_text .= "\n\n";
        }
        $comment_text .= <<<'END'
@FIXME
The $edit parameter is gone in Drupal 8. It has been left here in order to
prevent 'undefined variable' errors, but it will never actually be passed to
this hook. You'll need to modify this function and remove every reference to it.
END;
        $function->setDocComment(DocCommentNode::create($comment_text));
        $rewriter = $this->rewriters->createInstance('_rewriter:user');
        $this->rewriteFunction($rewriter, $function->getParameterAtIndex(0), $target);
        $target->save($function);
    }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // Prevent stupid effing 'undefined index' notices.
     $function = @($this->pluginDefinition['function'] ?: $this->getPluginId());
     $function_calls = $target->getIndexer('function_call')->get($function);
     foreach ($function_calls as $function_call) {
         // If the function call is no longer attached to a tree, don't even
         // try to rewrite it. This could happen when there are two calls to
         // the same function in a single statement, and the first one has
         // been commented out -- the second one will be attached to an orphaned
         // sub-tree, and this will result in fatal errors.
         if (!$function_call->hasRoot()) {
             continue;
         }
         $rewritten = $this->rewrite($function_call, $target);
         if (empty($rewritten)) {
             $statement = $function_call->getStatement();
             $rewritten = $statement->toComment();
             $statement->replaceWith($rewritten);
             $this->buildFixMe()->insertBefore($rewritten);
         } elseif ($rewritten !== $function_call) {
             $function_call->replaceWith($rewritten);
         }
         $target->save($rewritten);
     }
 }
Exemplo n.º 5
0
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        $indexer = $target->getIndexer('function');
        $hooks = array_filter($this->pluginDefinition['hook'], [$indexer, 'has']);
        foreach ($hooks as $hook) {
            /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
            $function = $indexer->get($hook);
            // The $edit parameter is defunct in Drupal 8, but we'll leave it in
            // there as an empty array to prevent errors, and move it to the back
            // of the line.
            /** @var \Pharborist\Functions\ParameterNode $edit */
            $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(NullNode::create());
            $function->appendParameter($edit);
            // Slap a FIXME on the hook implementation, informing the developer that
            // $edit and $category are dead.
            $comment = $function->getDocComment();
            $comment_text = $comment ? $comment->getCommentText() : '';
            if ($comment_text) {
                $comment_text .= "\n\n";
            }
            $comment_text .= <<<'END'
@FIXME
The $edit and $category parameters are gone in Drupal 8. They have been left
here in order to prevent 'undefined variable' errors, but they will never
actually be passed to this hook. You'll need to modify this function and
remove every reference to them.
END;
            $function->setDocComment(DocCommentNode::create($comment_text));
            $this->rewriteFunction($this->rewriter, $function->getParameterAtIndex(0), $target);
            $target->save($function);
        }
    }
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     /** @var \Symfony\Component\Finder\SplFileInfo $file */
     foreach ($this->target->getFinder() as $file) {
         $this->addFile($file->getPathname());
     }
 }
    /**
     * Helper for subclasses' rewrite() methods. This checks if the call can
     * be rewritten at all and leaves a FIXME if it can't. If the variable's
     * key is not a string starting with MODULE_, the call will not be
     * considered rewritable.
     *
     * @return boolean
     */
    protected function tryRewrite(FunctionCallNode $call, TargetInterface $target)
    {
        $statement = $call->getStatement();
        $arguments = $call->getArguments();
        if ($arguments[0] instanceof StringNode) {
            $key = $arguments[0]->toValue();
            if (strPos($key, $target->id() . '_') === 0) {
                return TRUE;
            } else {
                $comment = <<<END
This looks like another module's variable. You'll need to rewrite this call
to ensure that it uses the correct configuration object.
END;
                $this->buildFixMe($comment)->prependTo($statement);
                return FALSE;
            }
        } else {
            $comment = <<<END
The correct configuration object could not be determined. You'll need to
rewrite this call manually.
END;
            $this->buildFixMe($comment)->prependTo($statement);
            return FALSE;
        }
    }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // If the hook implementation contains logic, we cannot convert it and
     // that's that. So we'll leave a FIXME and bail out.
     /** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
     $hook = $target->getIndexer('function')->get('hook_menu');
     if ($hook->is(new ContainsLogicFilter())) {
         $hook->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
         $target->save($hook);
         return;
     }
     $hook_menu = new HookMenu($target, $this->routeConverters);
     foreach ($hook_menu->getSourceRoutes() as $path => $route) {
         /** @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper $route */
         if ($route->containsKey('page callback')) {
             $plugin_id = $this->routeConverters->hasDefinition($route['page callback']) ? $route['page callback'] : 'default';
             /** @var \Drupal\drupalmoduleupgrader\Routing\RouteConverterInterface $converter */
             $this->routeConverters->createInstance($plugin_id)->buildRoute($target, $route);
         }
     }
     $routing = [];
     foreach ($hook_menu->getDestinationRoutes() as $name => $route) {
         $routing[$name] = ['path' => $route->getPath()->__toString(), 'defaults' => $route->getDefaults(), 'requirements' => $route->getRequirements()];
     }
     $this->writeInfo($target, 'routing', $routing);
 }
 /**
  * @return \Pharborist\Objects\ClassNode
  */
 public function render()
 {
     if (empty($this->controller)) {
         $render = ['#theme' => 'dmu_form', '#module' => $this->target->id(), '#form_id' => $this->formID, '#class' => $this->toTitleCase($this->formID), '#config' => $this->isConfig];
         $source = \Drupal::service('renderer')->renderPlain($render);
         $this->controller = Parser::parseSource($source)->find(Filter::isClass($render['#class']))->get(0);
     }
     return $this->controller;
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $class_count = $target->getIndexer('class')->getQuery()->condition('type', 'Pharborist\\Objects\\ClassNode')->countQuery()->execute()->fetchField();
     if ($class_count > 0) {
         $issues[] = $this->buildIssue($target);
     }
     return $issues;
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function getName(TargetInterface $target, RouteWrapper $route)
 {
     $name = $target->id() . '.' . $this->unPrefix($route['page arguments'][0], $target->id());
     $arguments = array_filter(array_slice($route['page arguments'], 1), 'is_string');
     if ($arguments) {
         $name .= '_' . implode('_', $arguments);
     }
     return $name;
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $indexer = $target->getIndexer('function');
     if ($indexer->hasExecutable('hook_permission')) {
         $issues[] = $this->buildIssue($target)->addViolation($indexer->get('hook_permission'), $this)->addFix('hook_to_YAML', ['hook' => 'permission', 'destination' => '~/' . $target->id() . '.permissions.yml']);
     }
     return $issues;
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $hook = 'hook_' . $this->pluginDefinition['hook'];
     $indexer = $target->getIndexer('function');
     if ($indexer->has($hook)) {
         return [$this->buildIssue($target)->addViolation($indexer->get($hook), $this)];
     } else {
         return [];
     }
 }
 /**
  * Creates a FormConverter for a specific form.
  *
  * @param TargetInterface $target
  *  The module which defines the form.
  * @param string $form_id
  *  The original form ID.
  *
  * @return FormConverter
  *
  * @throws \BadMethodCallException if the target module doesn't define
  * the given form.
  */
 public function get(TargetInterface $target, $form_id)
 {
     $indexer = $target->getIndexer('function');
     if ($indexer->has($form_id)) {
         return new FormConverter($target, $form_id, $this->rewriter);
     } else {
         $message = $this->t('@target does not define form @form_id.', ['@target' => $target->id(), '@form_id' => $form_id]);
         throw new \BadMethodCallException($message);
     }
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $total = 0;
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalWebTestCase')->countQuery()->execute();
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalUnitTestCase')->countQuery()->execute();
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalTestBase')->countQuery()->execute();
     if ($total) {
         $issues[] = $this->buildIssue($target);
     }
     return $issues;
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $info_file = $target->getPath('.info');
     $info = self::parseInfo($info_file);
     $info['core'] = '8.x';
     $info['type'] = 'module';
     if (isset($info['dependencies'])) {
         // array_values() is called in order to reindex the array. Issue #2340207
         $info['dependencies'] = array_values(array_diff($info['dependencies'], ['ctools', 'list']));
     }
     unset($info['files'], $info['configure']);
     $this->writeInfo($target, 'info', $info);
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function_call');
     $issues = [];
     if ($indexer->has($this->pluginDefinition['function'])) {
         $issue = $this->buildIssue($target);
         $indexer->get($this->pluginDefinition['function'])->each(function (FunctionCallNode $function_call) use($issue) {
             $issue->addViolation($function_call, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
Exemplo n.º 18
0
 /**
  * Returns the collection of routes in the source.
  *
  * @return RouterInterface
  *   The requested link collection.
  */
 public function getSourceRoutes()
 {
     if (empty($this->sourceRoutes)) {
         $this->sourceRoutes = new Drupal7Router();
         $items = call_user_func($this->target->id() . '_menu');
         foreach ($items as $path => $item) {
             $this->sourceRoutes->addRoute(new Drupal7Route($path, $item));
         }
         // Now that all routes have been loaded, tell them to resolve their
         // hierarchical relationships.
         $this->sourceRoutes->finalize();
     }
     return $this->sourceRoutes;
 }
 public function convert(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function');
     $hooks = array_filter($this->pluginDefinition['hook'], [$indexer, 'has']);
     foreach ($hooks as $hook) {
         /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
         $function = $indexer->get($hook);
         $function->prependParameter(ParameterNode::create('build')->setTypeHint('array')->setReference(TRUE));
         // Extract the entity type from the hook name (e.g. 'hook_node_view').
         preg_match('/^hook_(.+)_view$/', $hook, $matches);
         $entity_type = $matches[1];
         $rewriter = $this->rewriters->createInstance('_rewriter:' . $entity_type);
         $this->rewriteFunction($rewriter, $function->getParameterAtIndex(1), $target);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function');
     // @FIXME This is not working (returns empty result set)...don't know why.
     $alter_hooks = $indexer->getQuery()->condition(db_or()->condition('id', $target->id() . '_form_alter')->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE'))->execute();
     foreach ($alter_hooks as $alter_hook) {
         /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
         $function = $indexer->get($alter_hook->id);
         $parameters = $function->getParameters();
         if (sizeof($parameters) > 1) {
             $parameters[1]->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
             $target->save($function);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
     $function = $target->getIndexer('function')->get('hook_node_prepare');
     // foo_node_prepare() --> foo_node_prepare_form().
     $function->setName($function->getName() . '_form');
     // The first parameter is a node, so rewrite the function accordingly.
     $this->rewriters->createInstance('_entity:node')->rewrite($function->getParameterAtIndex(0));
     // Create the $operation parameter.
     $function->appendParameter(ParameterNode::create('operation'));
     // Create the $form_state parameter.
     $form_state = ParameterNode::create('form_state')->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
     $function->appendParameter($form_state);
     $target->save($function);
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $function_calls = $target->getIndexer('function_call')->get($this->pluginDefinition['function'] ?: $this->getPluginId())->filter(function (FunctionCallNode $function_call) {
         $arguments = $function_call->getArguments();
         return $arguments[0] instanceof StringNode && in_array($arguments[0]->toValue(), self::$forbiddenTables);
     });
     $issues = [];
     if ($function_calls->count() > 0) {
         $issue = $this->buildIssue($target);
         $function_calls->each(function (FunctionCallNode $function_call) use($issue) {
             $issue->addViolation($function_call, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $this->target = $target;
     $mapping = ['DrupalWebTestCase' => 'convertWeb', 'AJAXTestCase' => 'convertAjax'];
     foreach ($mapping as $parent_class => $convert_method) {
         $test_files = $target->getIndexer('class')->getQuery(['file'])->condition('parent', $parent_class)->execute()->fetchCol();
         foreach ($test_files as $test_file) {
             /** @var \Pharborist\Objects\Classnode[] $tests */
             $tests = $target->open($test_file)->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))->toArray();
             foreach ($tests as $test) {
                 if ((string) $test->getExtends() === $parent_class) {
                     $this->{$convert_method}($test);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function');
     $issues = [];
     if ($indexer->has('hook_uninstall')) {
         /** @var \Pharborist\NodeCollection $variable_del */
         $variable_del = $indexer->get('hook_uninstall')->find(Filter::isFunctionCall('variable_del'));
         if (sizeof($variable_del) > 0) {
             $issue = $this->buildIssue($target);
             $variable_del->each(function (FunctionCallNode $function_call) use($issue) {
                 $issue->addViolation($function_call, $this);
             });
             $issues[] = $issue;
         }
     }
     return $issues;
 }
Exemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // If the hook implementation contains logic, we cannot convert it and
     // that's that. So we'll leave a FIXME and bail out.
     /** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
     $hook = $target->getIndexer('function')->get('hook_menu');
     if ($hook->is(new ContainsLogicFilter())) {
         $hook->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
         $target->save($hook);
         return;
     }
     // Links are split out by group because there are separate config files
     // for each link type.
     $links = ['menu' => new LinkIndex(), 'task' => new LinkIndex(), 'action' => new LinkIndex(), 'contextual' => new LinkIndex()];
     $hook_menu = new HookMenu($target, $this->routeConverters);
     foreach ($hook_menu->getSourceRoutes()->getAllLinks() as $path => $source) {
         /** @var LinkBinding $binding */
         $binding = $this->linkBinding->create($source, $hook_menu->getDestinationRoute($path));
         // Skip if the converter wasn't able to find a destination.
         $destination = $binding->getDestination();
         if (empty($destination)) {
             continue;
         }
         if ($binding instanceof MenuLinkBinding) {
             $links['menu']->addBinding($binding);
         } elseif ($binding instanceof LocalTaskLinkBinding) {
             $links['task']->addBinding($binding);
         } elseif ($binding instanceof LocalActionLinkBinding) {
             $links['action']->addBinding($binding);
         } elseif ($source->isContextualLink()) {
             $links['contextual']->addBinding($binding);
         }
     }
     $links = array_map(function (LinkIndex $index) {
         return $index->build();
     }, $links);
     foreach ($links['contextual'] as $link) {
         $link['group'] = $target->id();
     }
     foreach ($links as $group => $data) {
         if ($data) {
             $this->writeInfo($target, 'links.' . $group, $data);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $target->getIndexer('function')->get($this->pluginDefinition['hook'])->setDocComment($this->buildFixMe(NULL, [], self::DOC_COMMENT));
     $render = ['#theme' => 'dmu_route_subscriber', '#module' => $target->id()];
     $this->writeClass($target, $this->parse($render));
     $alterable = ParameterNode::create('data');
     $alterable->setTypeHint('array')->setReference(TRUE);
     $parameter = clone $alterable;
     $this->implement($target, 'menu_links_discovered_alter')->appendParameter($parameter->setName('links'));
     $parameter = clone $alterable;
     $this->implement($target, 'menu_local_tasks_alter')->appendParameter($parameter->setName('data'))->appendParameter(ParameterNode::create('route_name'));
     $parameter = clone $alterable;
     $this->implement($target, 'menu_local_actions_alter')->appendParameter($parameter->setName('local_actions'));
     $parameter = clone $alterable;
     $items = clone $alterable;
     $function = $this->implement($target, 'contextual_links_view_alter')->appendParameter($parameter->setName('element'))->appendParameter($items->setName('items')->setReference(FALSE));
     $target->save($function);
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target, $hook = NULL, $index = 0, $rewriter_id = NULL)
 {
     $indexer = $target->getIndexer('function');
     if (isset($hook)) {
         if ($indexer->has($hook)) {
             if (empty($rewriter_id)) {
                 // Extract the entity type from the hook (e.g. 'hook_node_delete').
                 preg_match('/^hook_(.+)_[a-z]+$/', $hook, $matches);
                 $rewriter_id = '_rewriter:' . $matches[1];
             }
             $rewriter = $this->rewriters->createInstance($rewriter_id);
             $this->rewriteFunction($rewriter, $indexer->get($hook)->getParameterAtIndex($index), $target);
         }
     } else {
         $this->convert($target, 'hook_comment_delete');
         $this->convert($target, 'hook_comment_insert');
         $this->convert($target, 'hook_comment_presave');
         $this->convert($target, 'hook_comment_update');
         $this->convert($target, 'hook_node_access');
         $this->convert($target, 'hook_node_access', 2, '_rewriter:account');
         $this->convert($target, 'hook_node_access_records', 0, '_rewriter:node');
         $this->convert($target, 'hook_node_access_records_alter', 1, '_rewriter:node');
         $this->convert($target, 'hook_node_delete');
         $this->convert($target, 'hook_node_grants', 0, '_rewriter:account');
         $this->convert($target, 'hook_node_grants_alter', 1, '_rewriter:account');
         $this->convert($target, 'hook_node_insert');
         $this->convert($target, 'hook_node_presave');
         $this->convert($target, 'hook_node_revision_delete');
         $this->convert($target, 'hook_node_search_result');
         $this->convert($target, 'hook_node_submit');
         $this->convert($target, 'hook_node_submit', 2, 'form_state');
         $this->convert($target, 'hook_node_update');
         $this->convert($target, 'hook_node_update_index');
         $this->convert($target, 'hook_node_validate');
         $this->convert($target, 'hook_node_validate', 2, 'form_state');
         $this->convert($target, 'hook_taxonomy_term_delete');
         $this->convert($target, 'hook_taxonomy_term_insert');
         $this->convert($target, 'hook_taxonomy_term_presave');
         $this->convert($target, 'hook_taxonomy_term_update');
         $this->convert($target, 'hook_user_delete');
         $this->convert($target, 'hook_user_logout');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $violations = [];
     $indexer = $target->getIndexer('function');
     if ($indexer->has('hook_form_alter')) {
         $violations[] = $indexer->get('hook_form_alter');
     }
     $id = $target->id() . '_form_%_alter';
     // Until kernel tests are run in PHPUnit, we need to check for
     // the existence of db_like().
     if (function_exists('db_like')) {
         $id = db_like($id);
     }
     $alter_hooks = $target->getIndexer('function')->getQuery()->condition('id', $id, 'LIKE')->execute();
     foreach ($alter_hooks as $alter_hook) {
         $violations[] = $target->open($alter_hook->file)->find(Filter::isFunction($alter_hook->id));
     }
     $issues = [];
     if ($violations) {
         $issue = $this->buildIssue($target);
         array_walk($violations, function (FunctionDeclarationNode $function) use($issue) {
             $issue->addViolation($function, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
Exemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $info_file = $target->getPath('.info');
     if (!file_exists($info_file)) {
         return $issues;
     }
     $info = \Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\InfoToYAML::parseInfo($info_file);
     if (empty($info)) {
         throw new \RuntimeException('Cannot parse info file ' . $info_file);
     }
     $doc = $this->pluginDefinition['documentation'][0];
     if ($info['core'] != '8.x') {
         $issues['core'] = new Issue($target, $this->t("Module info files' `core` key must have a value of `8.x`."));
         $issues['core']->addDocumentation($doc['url'], $doc['title']);
     }
     if (empty($info['type'])) {
         $issues['type'] = new Issue($target, $this->t('Info files must contain a `type` key.'));
         $issues['type']->addDocumentation($doc['url'] . '#type', $doc['title']);
     }
     if (isset($info['dependencies'])) {
         $issues['dependencies'] = new Issue($target, $this->t('Many common dependencies have moved into core.'));
         $issues['dependencies']->addDocumentation($doc['url'], $doc['title']);
     }
     if (isset($info['files'])) {
         $issues['files'] = new Issue($target, $this->t('Modules no longer declare classes in their info file.'));
         $issues['files']->addDocumentation($doc['url'] . '#files', $doc['title']);
     }
     if (isset($info['configure'])) {
         $issues['configure'] = new Issue($target, $this->t("Module info files' `configure` key must be a route name, not a path."));
         $issues['configure']->addDocumentation($doc['url'] . '#configure', $doc['title']);
     }
     /** @var \Drupal\drupalmoduleupgrader\IssueInterface $issue */
     foreach ($issues as $key => $issue) {
         $issue->setTag('error_level', 'error');
         $issue->setTag('category', ['info']);
         $issue->addAffectedFile($info_file, $this);
     }
     return $issues;
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     foreach ($this->configuration['function_calls'] as $function => $replace_with) {
         $function_calls = $target->getIndexer('function_call')->get($function);
         foreach ($function_calls as $function_call) {
             $rewritten = str_ireplace($function, $replace_with, $function_call->getText());
             $node = Parser::parseExpression($rewritten);
             $function_call->replaceWith($node);
             $target->save($node);
         }
     }
     // Flush other open syntax trees to ensure that other plugins don't clobber
     // our changes later.
     $target->flush();
     foreach ($target->getFinder() as $file) {
         // Load in the entire contents of the module. This is criminally inefficient
         // and wasteful of memory and should eventually be refactored into something
         // a little more...I dunno, sustainable.
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         $search = array_keys($this->targets);
         $replace = array_values($this->targets);
         file_put_contents($file->getPathname(), str_replace($search, $replace, $file->getContents()));
     }
 }