Completed
Pull Request — 8.x-3.x (#536)
by Sebastian
06:12 queued 03:59
created

JsonHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B decodeParams() 0 13 5
1
<?php
2
3
namespace Drupal\graphql\Utility;
4
5
class JsonHelper {
6
7
  /**
8
   * Decode encoded values recursively.
9
   *
10
   * @param array $values
11
   *   The values to decode.
12
   *
13
   * @return array
14
   *   The decoded values.
15
   */
16
  public static function decodeParams(array $values = []) {
17
    return array_map(function($value) {
18
      if (!is_string($value)) {
19
        return $value;
20
      }
21
22
      if (($decoded = json_decode($value, TRUE)) !== NULL && $decoded != $value) {
23
        return is_array($decoded) ? static::decodeParams($decoded) : $decoded;
24
      }
25
26
      return $value;
27
    }, $values);
28
  }
29
30
}
31