Completed
Push — 8.x-1.x ( 626d2d...5d8f74 )
by Frédéric G.
26s queued 12s
created

QaCommands   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 30
dl 0
loc 139
rs 10
c 1
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A graphviz() 0 3 1
A workflowsList() 0 6 1
A runPlugin() 0 16 2
A dependencies() 0 5 1
A systemUnused() 0 2 1
A table() 0 3 1
A __construct() 0 2 1
A referencesIntegrity() 0 2 1
A forceRemoved() 0 3 1
A referencesTaxonomyIndex() 0 2 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Drupal\qa\Commands;
6
7
use Drupal\qa\Controller\WorkflowsReportController;
8
use Drupal\qa\Plugin\QaCheck\References\Integrity;
9
use Drupal\qa\Plugin\QaCheck\References\TaxonomyIndex;
10
use Drupal\qa\Plugin\QaCheck\System\UnusedExtensions;
11
use Drupal\qa\Plugin\QaCheckManager;
12
use Drupal\qa\Workflows\ContentModerationGraph;
13
use Drupal\qa\Workflows\ContentModerationGrid;
14
use Drush\Commands\DrushCommands;
0 ignored issues
show
Bug introduced by
The type Drush\Commands\DrushCommands was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use OSInet\qa\ForceRemoved;
16
use Symfony\Component\Yaml\Yaml;
17
18
/**
19
 * A Drush commandfile.
20
 *
21
 * In addition to this file, you need a drush.services.yml
22
 * in root of your module, and a composer.json file that provides the name
23
 * of the services file to use.
24
 *
25
 * See these files for an example of injecting Drupal services:
26
 *   - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
27
 *   - http://cgit.drupalcode.org/devel/tree/drush.services.yml
28
 */
29
class QaCommands extends DrushCommands {
30
31
  /**
32
   * The plugin.manager.qa_check service.
33
   *
34
   * @var \Drupal\qa\Plugin\QaCheckManager
35
   */
36
  protected $qam;
37
38
  /**
39
   * QaCommands constructor.
40
   *
41
   * @param \Drupal\qa\Plugin\QaCheckManager $qam
42
   *   The plugin.manager.qa_check service.
43
   */
44
  public function __construct(QaCheckManager $qam) {
45
    $this->qam = $qam;
46
  }
47
48
  /**
49
   * Show the content moderation as a table.
50
   *
51
   * @command como:table
52
   * @aliases cmt,como-table
53
   */
54
  public function table() {
55
    $table = ContentModerationGrid::create(\Drupal::getContainer());
56
    $table->report();
57
  }
58
59
  /**
60
   * Show the content moderation as a Graphviz DOT file.
61
   *
62
   * @param string $workflow
63
   *   The machine name of a workflow.
64
   *
65
   * @command como:graphviz
66
   * @aliases cmg,como-graphviz
67
   */
68
  public function graphviz(string $workflow = '') {
69
    $graph = ContentModerationGraph::create(\Drupal::getContainer());
70
    echo $graph->report();
71
  }
72
73
  /**
74
   * Show a summary of available workflows.
75
   *
76
   * @command qa:workflows-list
77
   * @aliases qawl,qa-workflows-list
78
   */
79
  public function workflowsList() {
80
    $listBuilder = WorkflowsReportController::create(\Drupal::getContainer());
81
    $list = $listBuilder->getWorkflowSummary(
82
      $listBuilder->storage->loadMultiple()
83
    );
84
    $this->output->writeln(Yaml::dump($list));
85
  }
86
87
  /**
88
   * Build a Graphviz DOT file showing the module and theme dependencies.
89
   *
90
   * @command qa:dependencies
91
   * @aliases qadep,qa-dependencies
92
   */
93
  public function dependencies() {
94
    /** @var \Drupal\qa\Dependencies $qaDep */
95
    $qaDep = \Drupal::service('qa.dependencies');
96
    $g = $qaDep->build();
97
    echo $g->build();
98
  }
99
100
  /**
101
   * Command helper: runs a QaCheck plugin and display its results.
102
   *
103
   * @param string $name
104
   *   The plugin name.
105
   *
106
   * @throws \Drupal\Component\Plugin\Exception\PluginException
107
   */
108
  public function runPlugin(string $name): void {
109
    $check = $this->qam->createInstance($name);
110
    $pass = $check->run();
111
    $res = [
112
      'age' => $pass->life->age(),
113
      'ok' => $pass->ok,
114
      'result' => [],
115
    ];
116
    /** @var \Drupal\qa\Result $result */
117
    foreach ($pass->result as $key => $result) {
118
      $res['result'][$key] = [
119
        'ok' => $result->ok,
120
        'data' => $result->data,
121
      ];
122
    }
123
    $this->output->writeln(Yaml::dump($res, 5, 2));
124
  }
125
126
  /**
127
   * Show broken entity_reference fields.
128
   *
129
   * @command qa:references:integrity
130
   *
131
   * @throws \Drupal\Component\Plugin\Exception\PluginException
132
   */
133
  public function referencesIntegrity() {
134
    $this->runPlugin(Integrity::NAME);
135
  }
136
137
  /**
138
   * Show broken taxonomy_index data.
139
   *
140
   * @command qa:references:taxonomy_index
141
   *
142
   * @throws \Drupal\Component\Plugin\Exception\PluginException
143
   */
144
  public function referencesTaxonomyIndex() {
145
    $this->runPlugin(TaxonomyIndex::NAME);
146
  }
147
148
  /**
149
   * Show projects entirely unused and unused themes.
150
   *
151
   * @command qa:system:unused
152
   *
153
   * @throws \Drupal\Component\Plugin\Exception\PluginException
154
   */
155
  public function systemUnused() {
156
    $this->runPlugin(UnusedExtensions::NAME);
157
  }
158
159
  /**
160
   * List extensions removed without a clean uninstall.
161
   *
162
   * @command qa:force-removed
163
   * @aliases qafrm,qa-force-removed
164
   */
165
  public function forceRemoved() {
166
    $finder = ForceRemoved::create();
167
    echo $finder->find();
168
  }
169
170
}
171