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.uninstall.inc::df_admin_uninstall_scenario()   C

Complexity

Conditions 11
Paths 38

Size

Total Lines 106
Code Lines 54

Duplication

Lines 8
Ratio 7.55 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 11
eloc 54
c 1
b 0
f 1
nc 38
nop 1
dl 8
loc 106
rs 5.2653

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
 * @file
4
 * Contains DF Admin's uninstall command.
5
 */
6
7
/**
8
 * Page callback; uninstall a scenario.
9
 */
10
function df_admin_page_uninstall() {
11 View Code Duplication
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], DRUPAL_ROOT . '/df/uninstall')) {
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...
12
    return drupal_access_denied();
13
  }
14
  return df_admin_uninstall_scenario();
15
}
16
17
/**
18
 * Function to uninstall currently installed scenario
19
 */
20
function df_admin_uninstall_scenario($enable_module = FALSE) {
21
  // Check to see if any scenario is currently installed.
22
  if (!$scenario = variable_get('df_admin_installed_scenario', FALSE)) {
23
    drupal_set_message(t('No Demo Framework Scenario is currently installed.'));
24
    return FALSE;
25
  }
26
  else{
27
    drupal_set_message(t('Uninstalling Demo Framework Scenario @scenario', array('@scenario' => $scenario)));
28
  }
29
30
  // Load info file to grab dependencies.
31 View Code Duplication
  if (!$info = drupal_parse_info_file(drupal_get_path('module', $scenario) . '/' . $scenario . '.info')) {
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...
32
    drupal_set_message(t('Unable to load Scenario .info file'), 'error');
33
    return FALSE;
34
  }
35
36
  // Rollback Migrated content.
37
38
  // Get list of modules implementing Migrate API.
39
  migrate_get_module_apis();
40
41
  // Set up operations array.
42
  $operations = array();
43
44
  // Set up migrations array via hook_df_import().
45
  $migrations = module_invoke_all('df_import');
46
  drupal_alter('df_import', $migrations);
47
48
  // Check for available migrations based on the scenario.
49
  if (isset($migrations[$scenario]) && !empty($migrations[$scenario])) {
50
    // Queue migrations to rollback in the opposite order provided.
51 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...
52
      migrate_static_registration(array($machine_name));
53
      $operations[] = array('migrate_ui_batch', array('rollback', $machine_name, array('unit' => 'items', 'value' => ''), FALSE));
54
    }
55
  }
56
57
  // Uninstall features and the scenario.
58
59
  // Revert all Features for proper uninstall.
60
  df_admin_revert_all();
61
62
  // Gather list of feature dependencies.
63
  $features = array();
64
  foreach ($info['dependencies'] as $dependency) {
65
    if (strpos($dependency, 'dfs_') === 0) {
66
      $features[] = $dependency;
67
      $operations[] = array('drupal_set_message', array(t('Uninstalling @feature.', array('@feature' => $dependency)), 'status'));
68
    }
69
  }
70
71
  // Add this scenario onto features list so it is also removed.
72
  $features[] = $scenario;
73
74
  // Disable and uninstall features.
75
  $operations[] = array('module_disable', array($features));
76
  $operations[] = array('drupal_uninstall_modules', array($features));
77
  $operations[] = array('drupal_set_message', array(t('Uninstalled scenario and related features.'), 'status'));
78
79
  // Remove menu links.
80
81
  // Rebuild the menu_links table.
82
  $operations[] = array('db_query', array('TRUNCATE menu_links;'));
83
  $operations[] = array('menu_rebuild', array());
84
  $operations[] = array('drupal_set_message', array(t('Rebuilt menu_links table.'), 'status'));
85
86
  // Clear caches post-operations.
87
  $operations[] = array('drupal_flush_all_caches', array(''));
88
  $operations[] = array('drupal_set_message', array(t('All caches have been cleared.'), 'status'));
89
90
  // Clear messages for non-Drush users providing a cleaner scenario reset.
91
  if (!drupal_is_cli()) {
92
    $operations[] = array('drupal_get_messages', array(NULL, TRUE));
93
  }
94
95
  // Reset df_admin_installed_scenario variable.
96
  variable_set('df_admin_installed_scenario', FALSE);
97
98
  $batch = array(
99
    'operations' => $operations,
100
    'title' => t('Uninstall processing'),
101
    'init_message' => t('Starting uninstall process'),
102
    'file' => drupal_get_path('module', 'migrate_ui') . '/migrate_ui.pages.inc',
103
    'progress_message' => t('Uninstalling Demo Framework Scenario...'),
104
    'error_message' => t('An error occurred. Some or all of the uninstall processing has failed.'),
105
    'finished' => 'df_admin_batch_finish',
106
  );
107
  batch_set($batch);
108
  if (!drupal_is_cli()) {
109
    // If we're being called from the enable function, redirect to enable after
110
    // the current module is uninstalled.
111
    if ($enable_module) {
112
      $options = array('query' => array('token' => drupal_get_token(DRUPAL_ROOT . '/df/enable/' . $enable_module)));
113
      $path = array('admin/df/enable/' . $enable_module, $options);
114
    }
115
    else {
116
      $path = '';
117
    }
118
    batch_process($path);
119
  }
120
  else {
121
    drush_backend_batch_process();
122
  }
123
124
  return TRUE;
125
}
126