Completed
Pull Request — master (#152)
by
unknown
01:15
created

NodereferenceHandler::expand()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 9
Ratio 56.25 %

Importance

Changes 0
Metric Value
dl 9
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal7;
4
5
/**
6
 * Node reference field handler for Drupal 7.
7
 */
8
class NodereferenceHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $entity_type = 'node';
15
    $entity_info = entity_get_info($entity_type);
16
    $return = array();
17 View Code Duplication
    foreach ($values as $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
18
      $nid = db_select($entity_info['base table'], 't')
19
        ->fields('t', array($entity_info['entity keys']['id']))
20
        ->condition('t.' . $entity_info['entity keys']['label'], $value)
21
        ->execute()->fetchField();
22
      if ($nid) {
23
        $return[$this->language][] = array('nid' => $nid);
24
      }
25
    }
26
27
    return $return;
28
  }
29
}
30