Total Complexity | 8 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class Toolkit |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Convert url encoded string to array |
||
17 | * |
||
18 | * @param string $string |
||
19 | * @return array |
||
20 | */ |
||
21 | public static function urlDecode(string $string): array |
||
22 | { |
||
23 | $raw_data = explode('&', urldecode($string)); |
||
24 | $data = []; |
||
25 | |||
26 | foreach ($raw_data as $row) { |
||
27 | [$key, $value] = explode('=', $row); |
||
28 | |||
29 | if (self::isUrlEncode($value)) { |
||
30 | $value = urldecode($value); |
||
31 | if (self::isJson($value)) { |
||
32 | $value = json_decode($value, true); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | $data[$key] = $value; |
||
37 | } |
||
38 | |||
39 | return $data; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Check string is a url encoded string or not |
||
44 | * |
||
45 | * @param ?string $string |
||
46 | * @return bool |
||
47 | */ |
||
48 | public static function isUrlEncode(?string $string): bool |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Validate the given string is JSON or not |
||
59 | * |
||
60 | * @param ?string $string |
||
61 | * @return bool |
||
62 | */ |
||
63 | public static function isJson(?string $string): bool |
||
74 | } |