You are here

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

Analyzes a Drupal 7 module and reports the changes needed to port it to Drupal 8 or Drupal 9.

@option only A comma-separated list of analyzers to run, excluding all others. @option skip A comma-separated list of analyzers to skip. @option path Optional path to the target module. @option output Optional path to output the report. @usage drush dmu-analyze pants Analyze what needs to be changed in order to port the pants module.

@command dmu:analyze @aliases dmu-analyze

Parameters

string $module: The machine name of a Drupal 7 module.

array $options: Options supported by the command.

File

src/Commands/DrupalmoduleupgraderCommands.php, line 99

Class

DrupalmoduleupgraderCommands

Namespace

Drupal\drupalmoduleupgrader\Commands

Code

public function analyze(string $module, array $options = [
  'only' => NULL,
  'skip' => NULL,
  'path' => NULL,
  'output' => NULL,
]) {
  $target = $this
    ->dmuBuildTarget($module, $options['path']);
  $total_issues = 0;
  $report = new Report();
  foreach ($this
    ->dmuPluginList('analyzer', $options) as $id) {
    $this
      ->logger()
      ->info('Executing plugin: @plugin_id', [
      '@plugin_id' => $id,
    ]);
    $issues = $this->analyzerPluginManager
      ->createInstance($id)
      ->analyze($target);
    if ($issues) {
      if (!is_array($issues)) {
        $issues = [
          $issues,
        ];
      }
      foreach ($issues as $issue) {
        $report
          ->addIssue($issue);
      }
      $total_issues += sizeof($issues);
    }
  }
  if ($total_issues) {
    $render = [
      '#theme' => 'dmu_report',
      '#report' => $report,
    ];
    if (isset($options['output'])) {
      $destination = $options['output'];
    }
    else {
      $destination = $target
        ->getPath('upgrade-info.html');
    }
    $output = $this->renderer
      ->renderRoot($render);
    file_put_contents($destination, $output);
    $this
      ->logger()
      ->info('Generated a report at @path', [
      '@path' => $destination,
    ], 'success');
  }
  else {
    $this
      ->logger()
      ->info('Wow...no issues found! You get a cookie :)', 'success');
  }
}