You are here

public function InspectorCommands::inspect in Configuration Inspector 8

Inspect config for schema errors.

@option only-error Display only errors. @option detail Show detailed errors. @option skip-keys Configuration keys to skip.

@usage drush config:inspect Inspect whole config for schema errors. @usage drush config:inspect --detail Inspect whole config for schema errors but details errors. @usage drush config:inspect --only-error --detail Inspect whole config for schema errors and display only errors if any.

@field-labels key: Key status: Status @default-fields key,status

@command config:inspect @aliases inspect_config

Parameters

string $key: (Optional) Configuration key.

array $options: (Optional) Options array.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields List of inspections.

File

src/Commands/InspectorCommands.php, line 77

Class

InspectorCommands
Provides commands for config inspector.

Namespace

Drupal\config_inspector\Commands

Code

public function inspect($key = '', array $options = [
  'only-error' => FALSE,
  'detail' => FALSE,
  'skip-keys' => '',
]) {
  $rows = [];
  $exitCode = self::EXIT_SUCCESS;
  $keys = empty($key) ? $this->activeStorage
    ->listAll() : [
    $key,
  ];
  $onlyError = $options['only-error'];
  $detail = $options['detail'];
  $skipKeys = array_fill_keys(explode(',', $options['skip-keys']), '1');
  foreach ($keys as $name) {
    if (isset($skipKeys[$name])) {
      continue;
    }
    if (!$this->inspector
      ->hasSchema($name)) {
      $status = dt('No schema');
    }
    else {
      $result = $this->inspector
        ->checkValues($name);
      if (is_array($result)) {
        $exitCode = self::EXIT_FAILURE;
        if ($detail) {
          foreach ($result as $key => $error) {
            $rows[$key] = [
              'key' => $key,
              'status' => $error,
            ];
          }
          continue;
        }
        else {
          $status = dt('@count errors', [
            '@count' => count($result),
          ]);
        }
      }
      else {
        if ($onlyError) {
          continue;
        }
        $status = dt('Correct');
      }
    }
    $rows[$name] = [
      'key' => $name,
      'status' => $status,
    ];
  }
  return CommandResult::dataWithExitCode(new RowsOfFields($rows), $exitCode);
}