You are here

public function HookFormAlter::analyze in Drupal 7 to 8/9 Module Upgrader 8

Analyzes a target module and flags any issues found.

Parameters

TargetInterface $target: The target module.

Return value

\Drupal\drupalmoduleupgrader\IssueInterface[]

Overrides AnalyzerInterface::analyze

File

src/Plugin/DMU/Analyzer/HookFormAlter.php, line 31

Class

HookFormAlter
Plugin annotation @Analyzer( id = "hook_form_alter", description = @Translation("Checks for outdated hook_form_alter() implementations."), documentation = { { "url" =…

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer

Code

public function analyze(TargetInterface $target) {
  $violations = [];
  $indexer = $target
    ->getIndexer('function');
  if ($indexer
    ->has('hook_form_alter')) {
    $violations[] = $indexer
      ->get('hook_form_alter');
  }
  $query = $target
    ->getIndexer('function')
    ->getQuery();
  $alter_hooks = $query
    ->condition('id', $query
    ->escapeLike($target
    ->id() . '_form_') . '%' . $query
    ->escapeLike('_alter'), 'LIKE')
    ->execute();
  foreach ($alter_hooks as $alter_hook) {
    $violations[] = $target
      ->open($alter_hook->file)
      ->find(Filter::isFunction($alter_hook->id))
      ->get(0);
  }
  $issues = [];
  if ($violations) {
    $issue = $this
      ->buildIssue($target);
    array_walk($violations, function (FunctionDeclarationNode $function) use ($issue) {
      $issue
        ->addViolation($function, $this);
    });
    $issues[] = $issue;
  }
  return $issues;
}