Passed
Pull Request — 8.x-1.x (#16)
by Frédéric G.
05:02
created

QaCommands::externalCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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