GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DeepExplode::transform()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 22
rs 8.8333
c 0
b 0
f 0
cc 7
nc 6
nop 4
1
<?php
2
3
namespace Drupal\df_tools_migration\Plugin\migrate\process;
4
5
use Drupal\migrate\ProcessPluginBase;
6
use Drupal\migrate\MigrateException;
7
use Drupal\migrate\MigrateExecutableInterface;
8
use Drupal\migrate\Row;
9
10
/**
11
 * This plugin explodes a delimited string into an array of arrays.
12
 *
13
 * @MigrateProcessPlugin(
14
 *   id = "deep_explode"
15
 * )
16
 */
17
class DeepExplode extends ProcessPluginBase {
18
19
  /**
20
   * {@inheritdoc}
21
   */
22
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
23
    if (is_string($value)) {
24
      if (!empty($this->configuration['delimiter']) && !empty($this->configuration['nested_delimiter'])) {
25
        $items = explode($this->configuration['delimiter'], $value);
26
        $new_value = [];
27
        foreach ($items as $item) {
28
          if (is_string($item)) {
29
            $deep_item = explode($this->configuration['nested_delimiter'], $item);
30
            if (isset($this->configuration['nested_keys'])) {
31
              $deep_item = array_combine($this->configuration['nested_keys'], $deep_item);
32
            }
33
            $new_value[] = $deep_item;
34
          }
35
        }
36
        return $new_value;
37
      }
38
      else {
39
        throw new MigrateException('delimiter is empty');
40
      }
41
    }
42
    else {
43
      throw new MigrateException(sprintf('%s is not a string', var_export($value, TRUE)));
44
    }
45
  }
46
47
  /**
48
   * {@inheritdoc}
49
   */
50
  public function multiple() {
51
    return TRUE;
52
  }
53
54
}
55