Completed
Pull Request — master (#167)
by
unknown
01:26
created

DaterangeHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B expand() 0 26 6
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal8;
4
5
/**
6
 * Daterange field handler for Drupal 8.
7
 */
8
class DaterangeHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $return = [];
15
    foreach ($values as $value) {
16
      // Allow date ranges properties to be specified either explicitly,
17
      // or implicitly by array position.
18
      if (!isset($value['value']) && isset($value[0])) {
19
        $value['value'] = $value[0];
20
      }
21
      if (!isset($value['end_value'])) {
22
        if (isset($value[1])) {
23
          $value['end_value'] = $value[1];
24
        }
25
        else {
26
          // Allow end value to be optional (D#2794481).
27
          $value['end_value'] = NULL;
28
        }
29
      }
30
      $start = str_replace(' ', 'T', $value['value']);
31
      $end = str_replace(' ', 'T', $value['end_value']);
32
      $return[] = [
33
        'value' => $start,
34
        'end_value' => $end,
35
      ];
36
    }
37
    return $return;
38
  }
39
40
}
41