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 ( 9e29a0...ca9ee1 )
by Devin
07:35
created

DFSWEMNewsNodes::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 22
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 1
b 0
f 0
nc 1
nop 1
dl 22
loc 22
rs 9.2
1
<?php
2
3
/**
4
 * @file
5
 *  Migrations for WEM News Nodes.
6
 */
7
8
class DFSWEMNewsNodes extends DemoFrameworkBaseNodesUUID {
9
10 View Code Duplication
  public function __construct($arguments) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
11
    parent::__construct($arguments);
12
    $this->description = t('Import nodes.');
13
    $import_path = drupal_get_path('module', 'dfs_wem') . '/import/';
14
    // Create a MigrateSource object.
15
    $this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_news.csv', $this->csvcolumns(), array('header_rows' => 1));
16
    $this->destination = new MigrateDestinationNode('wem_news');
17
    // Image
18
    $this->addFieldMapping('field_wem_image', 'image');
19
    $this->addFieldMapping('field_wem_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
20
    $this->addFieldMapping('field_wem_image:source_dir')->defaultValue($import_path . 'images');
21
    $this->addFieldMapping('field_wem_image:destination_file', 'filename');
22
    // Video
23
    $this->addFieldMapping('field_wem_video', 'video')->sourceMigration('DFSWEMNewsVideo');
24
    $this->addFieldMapping('field_wem_video:file_class')->defaultValue('MigrateFileFid');
25
    // Taxonomy
26
    $this->addFieldMapping('field_wem_interests', 'interests');
27
    // Persona
28
    $this->addFieldMapping('field_persona', 'persona');
29
    // Site Section
30
    $this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Content");
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('title', 'Title');
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('body', 'Body');
36
    $columns[2] = array('image', 'Image');
37
    $columns[3] = array('video', 'Video');
38
    $columns[4] = array('interests', 'Interests');
39
    $columns[5] = array('uuid', 'UUID');
40
    $columns[6] = array('created', 'Created');
41
    $columns[7] = array('persona', 'Persona');
42
    return $columns;
43
  }
44
45
  function prepareRow($row) {
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...
46
    $row->interests = explode(", ", $row->interests);
47
    return TRUE;
48
  }
49
50
}
51
52 View Code Duplication
class DFSWEMNewsVideo extends Migration {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
53
  public function __construct($arguments) {
54
    parent::__construct($arguments);
55
    $this->map = new MigrateSQLMap($this->machineName,
56
      array(
57
        'video' => array(
58
          'type' => 'varchar',
59
          'length' => 255,
60
          'not null' => TRUE,
61
        ),
62
      ),
63
      MigrateDestinationFile::getKeySchema()
64
    );
65
    $this->destination = new MigrateDestinationFile('video', 'MigrateExtrasFileYoutube');
66
    $import_path = drupal_get_path('module', 'dfs_wem') . '/import/';
67
    $this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_news.csv', $this->csvcolumns(), array('header_rows' => 1));
68
    $this->addFieldMapping('value', 'video');
69
   }
70
71
  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...
72
    $columns[3] = array('video', 'Video');
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...
73
    return $columns;
74
  }
75
76
}
77
78