Completed
Pull Request — master (#85)
by
unknown
02:49
created

EntityreferenceHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 5
c 3
b 2
f 0
lcom 1
cbo 1
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B expand() 0 27 5
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal7;
4
5
/**
6
 * Entityreference field handler for Drupal 7.
7
 */
8
class EntityreferenceHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $result = array();
15
    $entity_type = $this->fieldInfo['settings']['target_type'];
16
    $entity_info = entity_get_info($entity_type);
17
    // For users set label to username.
18
    if ($entity_type == 'user') {
19
      $entity_info['entity keys']['label'] = 'name';
20
    }
21
22
    foreach ($values as $value) {
23
      $query = db_select($entity_info['base table'], 't')
24
        ->fields('t', array($entity_info['entity keys']['id']));
25
      if (is_numeric($value)) {
26
        $query->condition('t.' . $entity_info['entity keys']['id'], $value);
27
      }
28
      else {
29
        $query->condition('t.' . $entity_info['entity keys']['label'], $value);
30
      }
31
      $str_query = (string) $query;
0 ignored issues
show
Unused Code introduced by
$str_query 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...
32
      $str_arguments = print_r($query->getArguments(), TRUE);
0 ignored issues
show
Unused Code introduced by
$str_arguments 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...
33
      $target_id = $query->execute()->fetchField();
34
      if ($target_id) {
35
        $result[$this->language][] = array('target_id' => $target_id);
36
      }
37
    }
38
    return $result;
39
  }
40
41
}
42