1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Drush plugin. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use Drupal\qa\Controller\WorkflowsReportController; |
9
|
|
|
use Drupal\qa\Workflows\ContentModerationGraph; |
10
|
|
|
use Drupal\qa\Workflows\ContentModerationGrid; |
11
|
|
|
use Drupal\qa\Workflows\WorkflowList; |
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
13
|
|
|
|
14
|
|
|
use OSInet\qa\ForceRemoved; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Implementation of hook_drush_command(). |
18
|
|
|
*/ |
19
|
|
|
function qa_drush_command() { |
20
|
|
|
$items['como-table'] = [ |
|
|
|
|
21
|
|
|
'aliases' => ['cmt'], |
22
|
|
|
'description' => 'Show the content moderation as a table.', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
$items['como-graphviz'] = [ |
26
|
|
|
'aliases' => ['cmg'], |
27
|
|
|
'description' => 'Show the content moderation as a Graphviz DOT file.', |
28
|
|
|
'arguments' => [ |
29
|
|
|
'workflow' => 'The machine name of a workflow', |
30
|
|
|
] |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
$items['qa-workflows-list'] = [ |
34
|
|
|
'aliases' => ['qawl'], |
35
|
|
|
'description' => 'Show a summary of available workflows', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
$items['qa-dependencies'] = [ |
39
|
|
|
'description' => 'Build a Graphviz DOT file showing the module and theme dependencies on the site', |
40
|
|
|
'aliases' => ['qadep'], |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$items['qa-force-removed'] = [ |
44
|
|
|
'description' => 'List extensions removed without a clean uninstall.', |
45
|
|
|
'aliases' => ['qafrm'], |
46
|
|
|
]; |
47
|
|
|
return $items; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function drush_qa_como_graphviz() { |
51
|
|
|
$graph = ContentModerationGraph::create(\Drupal::getContainer()); |
52
|
|
|
echo $graph->report(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Command callback for qa-workflows-list. |
57
|
|
|
*/ |
58
|
|
|
function drush_qa_workflows_list() { |
59
|
|
|
$listBuilder = WorkflowsReportController::create(Drupal::getContainer()); |
60
|
|
|
$list = $listBuilder->getWorkflowSummary( |
61
|
|
|
$listBuilder->storage->loadMultiple() |
62
|
|
|
); |
63
|
|
|
drush_print(Yaml::dump($list)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function drush_qa_como_table() { |
67
|
|
|
$table = ContentModerationGrid::create(\Drupal::getContainer()); |
68
|
|
|
$table->report(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function drush_qa_dependencies() { |
72
|
|
|
module_load_include('inc', 'qa', 'qa_dependencies'); |
73
|
|
|
$G = qa_dependencies(); |
74
|
|
|
echo $G->parse(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function drush_qa_force_removed() { |
78
|
|
|
$finder = ForceRemoved::create(); |
79
|
|
|
echo $finder->find(); |
80
|
|
|
} |
81
|
|
|
|
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:
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 thebar
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.