ListTextHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B expand() 0 25 6
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal7;
4
5
/**
6
 * ListText field handler for Drupal 7.
7
 */
8
class ListTextHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $return = [];
15
    $allowed_values = [];
16
    if (!empty($this->fieldInfo['settings']['allowed_values_function'])) {
17
      $cacheable = TRUE;
18
      $callback = $this->fieldInfo['settings']['allowed_values_function'];
19
      $options = call_user_func($callback, $this->fieldInfo, $this, $this->entityType, $this->entity, $cacheable);
20
    }
21
    else {
22
      $options = $this->fieldInfo['settings']['allowed_values'];
23
    }
24
    foreach ($values as $value) {
25
      if (array_key_exists($value, $options)) {
26
        $allowed_values[$value] = $value;
27
      }
28
      elseif (in_array($value, $options)) {
29
        $key = array_search($value, $options);
30
        $allowed_values[$value] = $key;
31
      }
32
    }
33
    foreach ($values as $value) {
34
      $return[$this->language][] = ['value' => $allowed_values[$value]];
35
    }
36
    return $return;
37
  }
38
39
}
40