Completed
Pull Request — master (#156)
by
unknown
01:19
created

CommerceProductReferenceHandler::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
 * CommerceProductReference field handler for Drupal 7.
7
 */
8
class CommerceProductReferenceHandler extends AbstractHandler {
9
  /**
10
   * {@inheritdoc}
11
   */
12
  public function expand($values) {
13
    $entity_type = 'commerce_product'; // $this->fieldInfo['settings']['target_type'];
14
    $entity_info = entity_get_info($entity_type);
15
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
      $product_id = 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 ($product_id) {
23
        $return[$this->language][] = array('product_id' => $product_id);
24
      }
25
    }
26
    return $return;
27
  }
28
}
29