These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @file |
||
5 | * Drush plugin. |
||
6 | */ |
||
7 | |||
8 | use Drupal\qa\ForceRemoved; |
||
9 | use Drupal\qa\System\ProjectsScanner; |
||
10 | |||
11 | /** |
||
12 | * Implementation of hook_drush_command(). |
||
13 | */ |
||
14 | function qa_drush_command() { |
||
15 | $items['qa-dependencies'] = [ |
||
0 ignored issues
–
show
|
|||
16 | 'description' => 'Build a Graphviz DOT file showing the module and theme dependencies on the site', |
||
17 | 'aliases' => ['qadep'], |
||
18 | ]; |
||
19 | |||
20 | $items['qa-force-removed'] = [ |
||
21 | 'description' => 'List extensions removed without a clean uninstall.', |
||
22 | 'aliases' => ['qafrm'], |
||
23 | ]; |
||
24 | |||
25 | $items['qa-project-usage'] = [ |
||
26 | 'description' => 'List usage and components for projects', |
||
27 | 'options' => [ |
||
28 | 'only-unused' => 'Only include totally unused packages', |
||
29 | ], |
||
30 | 'aliases' => ['qapus'], |
||
31 | ]; |
||
32 | |||
33 | return $items; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Command callback for qa-dependencies. |
||
38 | */ |
||
39 | function drush_qa_dependencies() { |
||
40 | module_load_include('inc', 'qa', 'qa_dependencies'); |
||
41 | $G = qa_dependencies(); |
||
42 | echo $G->parse(); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Command callback for qa-force-removed. |
||
47 | */ |
||
48 | function drush_qa_force_removed() { |
||
49 | $finder = ForceRemoved::create(); |
||
50 | echo $finder->find(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Command callback for qa-project-usage. |
||
55 | */ |
||
56 | function drush_qa_project_usage() { |
||
57 | $onlyUnused = drush_get_option('only-unused', FALSE); |
||
58 | $scanner = new ProjectsScanner(); |
||
59 | $result = $scanner->scan($onlyUnused); |
||
60 | echo json_encode($result, JSON_PRETTY_PRINT) . "\n"; |
||
61 | } |
||
62 |
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.