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

EntityreferenceHandler::expand()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 27
rs 8.439
cc 5
eloc 19
nc 10
nop 1
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