OSInet /
qa
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 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 |
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.