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 ( 34e25a...94dab8 )
by Devin
03:48
created

DFUsers::csvcolumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 14
rs 9.4285
c 2
b 0
f 0
1
<?php
2
3
/**
4
 *  @file
5
 *   Contains base User migration class
6
 */
7
8
class DFUsers extends ImportBaseUsers {
9
10
  public function __construct($arguments) {
11
    parent::__construct($arguments);
12
    // Create a MigrateSource object.
13
    if (isset($arguments['path'])) {
14
      $import_path = $arguments['path'];
15
    }
16
    else {
17
      $import_path = drupal_get_path('module', 'df_tools_user') . '/import/df_tools_user.users.csv';
18
    }
19
    $this->source = new MigrateSourceCSV($import_path, $this->csvcolumns(), array('header_rows' => 1));
20
21
    $picture_source = isset($arguments['picture_source']) ? $arguments['picture_source'] : 'DFUserPictures';
22
    $this->addFieldMapping('picture', 'picture')->sourceMigration($picture_source);
23
    $this->addFieldMapping('field_user_interests', 'interests');
24
    $this->addFieldMapping('field_user_bio', 'bio');
25
    $this->addFieldMapping('field_user_bio:format')->defaultValue('userbase');
26
    $this->addFieldMapping('field_user_first', 'first');
27
    $this->addFieldMapping('field_user_last', 'last');
28
    // Last login
29
    $this->addFieldMapping('login', 'access')->defaultValue(strtotime("-1 week"));
30
    $this->addFieldMapping('login', 'login')->defaultValue(strtotime("-1 week"));
31
  }
32
33
  function csvcolumns() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
    $columns[0] = array('name', 'Name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

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:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

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 the bar 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.

Loading history...
35
    $columns[1] = array('pass', 'Pass');
36
    $columns[2] = array('mail', 'Mail');
37
    $columns[3] = array('status', 'Status');
38
    $columns[4] = array('roles', 'Roles');
39
    $columns[5] = array('picture', 'Picture');
40
    $columns[6] = array('interests', 'Interests');
41
    $columns[7] = array('bio', 'Bio');
42
    $columns[8] = array('first', 'First');
43
    $columns[9] = array('last', 'Last');
44
    $columns[10] = array('login', 'Last Login');
45
    return $columns;
46
  }
47
48
  public function prepareRow($row) {
49
    $user_roles = explode(", ", $row->roles);
50
    $roles = array('2' => '2');
51
    foreach ($user_roles as $role_name) {
52
      $rid = db_query('SELECT rid FROM {role} WHERE name = :name', array(':name' => $role_name))->fetchField();
53
      $roles[$rid] = $rid;
54
    }
55
    $row->roles = $roles;
56
    $row->interests = explode(", ", $row->interests);
57
    // Convert date string in csv to a datetime
58
    if (isset($row->login)) {
59
      $row->login = strtotime($row->login);
60
    }
61
    return TRUE;
62
  }
63
64
}
65
66
class DFUserPictures extends ImportBaseUserPictures {
67
  public function __construct($arguments) {
68
    parent::__construct($arguments);
69
    if (isset($arguments['path'])) {
70
      $import_path = $arguments['path'];
71
    }
72
    else {
73
      $import_path = drupal_get_path('module', 'df_tools_user') . '/import/df_tools_user.users.csv';
74
    }
75
    $this->source = new MigrateSourceCSV($import_path, $this->csvcolumns(), array('header_rows' => 1));
76
77
    // Get the base path, which is where we assume /images is located
78
    $base_path = dirname($import_path);
79
    $this->addFieldMapping('source_dir')->defaultValue($base_path . '/images');
80
  }
81
82
  function csvcolumns() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    $columns[5] = array('picture', 'Picture');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$columns was never initialized. Although not strictly required by PHP, it is generally a good practice to add $columns = array(); before regardless.

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:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

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 the bar 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.

Loading history...
84
    return $columns;
85
  }
86
87
}
88