Completed
Push — 8.x-1.x ( 3c8412...894b5c )
by Frédéric G.
01:50
created

qa.drush.inc::drush_qa_workflows_list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use Drupal\qa\Controller\WorkflowsReportController;
4
use Drupal\qa\Workflows\ContentModerationGraph;
5
use Drupal\qa\Workflows\ContentModerationGrid;
6
use Drupal\qa\Workflows\WorkflowList;
7
use Symfony\Component\Yaml\Yaml;
8
9
function qa_drush_command() {
10
  $items['como-table'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
11
    'aliases' => ['cmt'],
12
    'description' => 'Show the content moderation as a table.',
13
  ];
14
15
  $items['como-graphviz'] = [
16
    'aliases' => ['cmg'],
17
    'description' => 'Show the content moderation as a Graphviz DOT file.',
18
    'arguments' => [
19
      'workflow' => 'The machine name of a workflow',
20
    ]
21
  ];
22
23
  $items['qa-workflows-list'] = [
24
    'aliases' => ['qawl'],
25
    'description' => 'Show a summary of available workflows',
26
  ];
27
28
  return $items;
29
}
30
31
function drush_qa_como_graphviz() {
32
  $graph = ContentModerationGraph::create(\Drupal::getContainer());
33
  echo $graph->report();
34
}
35
36
/**
37
 * Command callback for qa-workflows-list.
38
 */
39
function drush_qa_workflows_list() {
40
  $listBuilder = WorkflowsReportController::create(Drupal::getContainer());
41
  $list = $listBuilder->getWorkflowSummary(
42
    $listBuilder->storage->loadMultiple()
43
  );
44
  drush_print(Yaml::dump($list));
45
}
46
47
function drush_qa_como_table() {
48
  $table = ContentModerationGrid::create(\Drupal::getContainer());
49
  $table->report();
50
}
51
52