ListBooleanHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A expand() 0 15 4
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal7;
4
5
/**
6
 * ListBoolean field handler for Drupal 7.
7
 */
8
class ListBooleanHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $return = [];
15
    $allowed_values = $this->fieldInfo['settings']['allowed_values'];
16
    // If values are blank then use keys as value.
17
    foreach ($allowed_values as $key => $value) {
18
      if ($value == '') {
19
        $allowed_values[$key] = $key;
20
      }
21
    }
22
    $allowed_values = array_flip($allowed_values);
23
    foreach ($values as $value) {
24
      $return[$this->language][] = ['value' => $allowed_values[$value]];
25
    }
26
    return $return;
27
  }
28
29
}
30