Completed
Push — 8.x-3.x ( e0ffee...44ec71 )
by Sebastian
02:11
created

JsonHelper::decodeParams()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 9.2
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 static::decodeParams($decoded);
24
      }
25
26
      return $value;
27
    }, $values);
28
  }
29
30
}