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

DFSWEMContestNodes   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 25.64 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 10
loc 39
rs 10
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A csvcolumns() 10 10 1
A prepareRow() 0 4 1
A __construct() 0 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @file
5
 *  Migrations for WEM Contest Nodes.
6
 */
7
8
class DFSWEMContestNodes extends DemoFrameworkBaseNodesUUID {
9
10
  public function __construct($arguments) {
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_contest.csv', $this->csvcolumns(), array('header_rows' => 1));
16
    $this->destination = new MigrateDestinationNode('wem_contest');
17
    // Image
18
    $this->addFieldMapping('field_contest_image', 'image');
19
    $this->addFieldMapping('field_contest_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
20
    $this->addFieldMapping('field_contest_image:source_dir')->defaultValue($import_path . 'images');
21
    $this->addFieldMapping('field_contest_image:destination_file', 'filename');
22
    // Taxonomy
23
    $this->addFieldMapping('field_contest_interests', 'interests');
24
    // Persona
25
    $this->addFieldMapping('field_persona', 'persona');
26
    // Site Section
27
    $this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Community");
28
  }
29
30 View Code Duplication
  function csvcolumns() {
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...
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...
31
    $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...
32
    $columns[1] = array('body', 'Body');
33
    $columns[2] = array('image', 'Image');
34
    $columns[3] = array('interests', 'Interests');
35
    $columns[4] = array('uuid', 'UUID');
36
    $columns[5] = array('created', 'Created');
37
    $columns[6] = array('persona', 'Persona');
38
    return $columns;
39
  }
40
41
  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...
42
    $row->interests = explode(", ", $row->interests);
43
    return TRUE;
44
  }
45
46
}
47
48