You are here

public function HackedCommands::details in Hacked! 8.2

Show the Hacked! report about a specific project.

@option include-unchanged Show the files that are unchanged too. @command hacked:details @aliases hd,hacked-details

@validate-module-enabled hacked

@field-labels status: Status file: File @default-fields status,file

Parameters

string $machine_name: The machine name of the project to report on.

array $options: An associative array of options whose values come from cli, aliases, config, etc.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields Report data arranged for table display.

File

src/Commands/HackedCommands.php, line 173

Class

HackedCommands
A Drush commandfile for Hacked! module.

Namespace

Drupal\hacked\Commands

Code

public function details($machine_name, array $options = [
  'include-unchanged' => FALSE,
]) {
  $project = new hackedProject($machine_name);
  $report = $project
    ->compute_details();
  $this
    ->output()
    ->writeln((string) $this
    ->t('Details for project: @name', [
    '@name' => $project
      ->title(),
  ]));
  $this
    ->output()
    ->writeln((string) $this
    ->t('Total files: @total_files, files changed: @changed_files, deleted files: @deleted_files', [
    '@total_files' => count($report['files']),
    '@changed_files' => $report['counts']['different'],
    '@deleted_files' => $report['counts']['missing'],
  ]));
  $this
    ->output()
    ->writeln('');
  $this
    ->output()
    ->writeln((string) $this
    ->t('Detailed results:'));

  // Sort the results.
  arsort($report['files']);
  $rows = [];
  $show_unchanged = $options['include-unchanged'];
  foreach ($report['files'] as $file => $status) {
    if (!$show_unchanged && $status == HACKED_STATUS_UNHACKED) {
      continue;
    }
    $row = [];

    // Now add the status.
    switch ($status) {
      case HACKED_STATUS_UNHACKED:
        $row['status'] = $this
          ->t('Unchanged');
        break;
      case HACKED_STATUS_HACKED:
        $row['status'] = $this
          ->t('Changed');
        break;
      case HACKED_STATUS_DELETED:
        $row['status'] = $this
          ->t('Deleted');
        break;
      case HACKED_STATUS_UNCHECKED:
      default:
        $row['status'] = $this
          ->t('Unchecked');
        break;
    }
    $row['file'] = $file;
    $rows[] = $row;
  }
  return new RowsOfFields($rows);
}