GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 7.x-1.x ( 94dab8...029788 )
by Devin
03:44
created

modules/df/df_admin/df_admin.reset.inc::df_admin_reset_scenario()   F

Complexity

Conditions 19
Paths 721

Size

Total Lines 131
Code Lines 72

Duplication

Lines 10
Ratio 7.63 %

Importance

Changes 10
Bugs 3 Features 4
Metric Value
cc 19
eloc 72
c 10
b 3
f 4
nc 721
nop 3
dl 10
loc 131
rs 2.3386

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @file
5
 * DF Admin's reset page handling functions.
6
 */
7
8
/**
9
 * Page callback; reset a scenario.
10
 */
11
function df_admin_page_reset($module) {
12 View Code Duplication
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], DRUPAL_ROOT . '/df/reset/' . $module)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    return drupal_access_denied();
14
  }
15
  return df_admin_reset_scenario($module, TRUE, TRUE);
16
}
17
18
/**
19
 * Function to process migrations in correct order to safely inject DFS
20
 * content into the system.
21
 */
22
function df_admin_reset_scenario($scenario, $rollback = TRUE, $seed = TRUE) {
23
  // Check to see if scenario is not enabled.
24
  if (!module_exists($scenario)) {
25
    drupal_set_message(t('@scenario must be enabled before a reset can occur.', array('@scenario' => $scenario)), 'error');
26
    return FALSE;
27
  }
28
29
  // Get list of modules implementing Migrate API.
30
  migrate_get_module_apis();
31
32
  // Set up operations array.
33
  $operations = array();
34
35
  // Revert Features to ensure proper DFS reset.
36
  $operations[] = array('df_admin_revert_all', array(''));
37
  $operations[] = array('drupal_set_message', array(t('Reverted Features after scenario enablement.'), 'status'));
38
  $operations[] = array('_df_admin_watchdog_revert_features', array($scenario));
39
40
  // Rebuild defaultconfig from modules.
41
  $operations[] = array('defaultconfig_rebuild_all', array(''));
42
  $operations[] = array('drupal_set_message', array(t('Defaultconfig rebuilt after scenario enablement.'), 'status'));
43
  $operations[] = array('_df_admin_watchdog_defaultconfig_rebuild', array($scenario));
44
45
  // Set up pre-import routines via hook_df_pre_import().
46
  $routines = array();
0 ignored issues
show
Unused Code introduced by
$routines is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
  $routines = module_invoke_all('df_pre_import');
48
  drupal_alter('df_pre_import', $routines);
49
50
  // Add pre-import functions to the batch process.
51
  foreach ($routines as $routine) {
52
    $operations[] = $routine;
53
  }
54
55
  // Set up migrations array via hook_df_import().
56
  $migrations = array();
0 ignored issues
show
Unused Code introduced by
$migrations is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
  $migrations = module_invoke_all('df_import');
58
  drupal_alter('df_import', $migrations);
59
60
  // Check for available migrations based on the scenario argument.
61
  if (isset($migrations[$scenario]) && !empty($migrations[$scenario])) {
62
63
    if ($rollback == TRUE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
64
      // Queue migrations to rollback in the opposite order provided.
65 View Code Duplication
      foreach (array_reverse($migrations[$scenario]) as $machine_name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
        migrate_static_registration(array($machine_name));
67
        $migration = Migration::getInstance($machine_name);
0 ignored issues
show
Unused Code introduced by
$migration is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
        $operations[] = array('migrate_ui_batch', array('rollback', $machine_name, array('unit' => 'items', 'value' => ''), FALSE));
69
      }
70
    }
71
72
    // Queue migrations to import in the provided order.
73 View Code Duplication
    foreach ($migrations[$scenario]  as $machine_name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
      migrate_static_registration(array($machine_name));
75
      $migration = Migration::getInstance($machine_name);
0 ignored issues
show
Unused Code introduced by
$migration is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
      $operations[] = array('migrate_ui_batch', array('import', $machine_name, array('unit' => 'items', 'value' => ''), FALSE));
77
    }
78
79
    // Confirm if there was an attempt to run scenario migrations.
80
    $migrations_count = count($migrations[$scenario]);
81
    if ($migrations_count > 0 && drupal_is_cli()) {
82
      $message = $migrations_count . ' demo migrations attempted.';
83
      $operations[] = array('drush_print', array($message, 0, NULL, TRUE));
84
    }
85
86
  }
87
88
  // Set up post-import routines via hook_df_post_import().
89
  $routines = array();
0 ignored issues
show
Unused Code introduced by
$routines is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
90
  $routines = module_invoke_all('df_post_import');
91
  drupal_alter('df_post_import', $routines);
92
93
  // Add post-import functions to the batch process.
94
  foreach ($routines as $routine) {
95
    $operations[] = $routine;
96
  }
97
98
  // Clear caches post-operations.
99
  $operations[] = array('node_access_rebuild', array(''));
100
  $operations[] = array('drupal_flush_all_caches', array(''));
101
  $operations[] = array('variable_set', array('menu_rebuild_needed', TRUE));
102
  $operations[] = array('drupal_set_message', array(t('All caches have been cleared.'), 'status'));
103
  $operations[] = array('_df_admin_watchdog_cache_clear', array($scenario));
104
105
  // Clear messages for non-Drush users providing a cleaner scenario reset.
106
  if (!drupal_is_cli()) {
107
    $messages = array('completed', 'status', 'warning');
108
    foreach ($messages as $message) {
109
      $operations[] = array('drupal_get_messages', array($message, TRUE));
110
    }
111
  }
112
  else {
113
    // Determine the current alias
114
    $alias_context = drush_get_context('alias');
115
    $alias = !empty($alias_context) ? $alias_context : '@self';
116
117
    // Seed derivatives
118
    if ($seed == TRUE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
119
      $operations[] = array('drush_invoke_process', array($alias, 'df-sd', array(), array(), TRUE));
120
    }
121
    // Clear caches before we start the batch, to prevent conflicts with new module additions
122
    // This fixes a specific bug with the --pre option, but there's no harm in calling it every time df-rs is called
123
    drush_invoke_process($alias, 'cc', array('all'));
124
  }
125
126
  // Rollback and Import migration operations via Batch API.
127
  if (count($operations) > 0) {
128
    $batch = array(
129
      'operations' => $operations,
130
      'title' => t('Import processing'),
131
      'init_message' => t('Starting import process'),
132
      'file' => drupal_get_path('module', 'migrate_ui') . '/migrate_ui.pages.inc',
133
      'progress_message' => t('Importing Demo Framework Scenario...'),
134
      'error_message' => t('An error occurred. Some or all of the import processing has failed.'),
135
      'finished' => 'df_admin_batch_finish',
136
    );
137
    batch_set($batch);
138
    if (!drupal_is_cli()) {
139
      $options = array('query' => array('token' => drupal_get_token(DRUPAL_ROOT . '/df/imagestyles')));
140
      // The ability to send an array for $redirect is undocumented on Drupal.org, yay!
141
      batch_process(array('admin/df/imagestyles', $options));
142
    }
143
    else {
144
      drush_backend_batch_process();
145
    }
146
  }
147
  // No operations present, non-drush users get redirected.
148
  if (!drupal_is_cli() && empty($operations)) {
149
    drupal_goto('');
150
  }
151
  return TRUE;
152
}
153