Completed
Push — 8.x-3.x ( 6dfa31...13bbe7 )
by Sebastian
07:50 queued 05:30
created

JsonHelper::decodeParams()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
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