@@ -9,68 +9,68 @@ |
||
9 | 9 | namespace OC\Core\Command\Config\System; |
10 | 10 | |
11 | 11 | class CastHelper { |
12 | - /** |
|
13 | - * @return array{value: mixed, readable-value: string} |
|
14 | - */ |
|
15 | - public function castValue(?string $value, string $type): array { |
|
16 | - switch ($type) { |
|
17 | - case 'integer': |
|
18 | - case 'int': |
|
19 | - if (!is_numeric($value)) { |
|
20 | - throw new \InvalidArgumentException('Non-numeric value specified'); |
|
21 | - } |
|
22 | - return [ |
|
23 | - 'value' => (int)$value, |
|
24 | - 'readable-value' => 'integer ' . (int)$value, |
|
25 | - ]; |
|
12 | + /** |
|
13 | + * @return array{value: mixed, readable-value: string} |
|
14 | + */ |
|
15 | + public function castValue(?string $value, string $type): array { |
|
16 | + switch ($type) { |
|
17 | + case 'integer': |
|
18 | + case 'int': |
|
19 | + if (!is_numeric($value)) { |
|
20 | + throw new \InvalidArgumentException('Non-numeric value specified'); |
|
21 | + } |
|
22 | + return [ |
|
23 | + 'value' => (int)$value, |
|
24 | + 'readable-value' => 'integer ' . (int)$value, |
|
25 | + ]; |
|
26 | 26 | |
27 | - case 'double': |
|
28 | - case 'float': |
|
29 | - if (!is_numeric($value)) { |
|
30 | - throw new \InvalidArgumentException('Non-numeric value specified'); |
|
31 | - } |
|
32 | - return [ |
|
33 | - 'value' => (float)$value, |
|
34 | - 'readable-value' => 'double ' . (float)$value, |
|
35 | - ]; |
|
27 | + case 'double': |
|
28 | + case 'float': |
|
29 | + if (!is_numeric($value)) { |
|
30 | + throw new \InvalidArgumentException('Non-numeric value specified'); |
|
31 | + } |
|
32 | + return [ |
|
33 | + 'value' => (float)$value, |
|
34 | + 'readable-value' => 'double ' . (float)$value, |
|
35 | + ]; |
|
36 | 36 | |
37 | - case 'boolean': |
|
38 | - case 'bool': |
|
39 | - $value = strtolower($value); |
|
40 | - return match ($value) { |
|
41 | - 'true' => [ |
|
42 | - 'value' => true, |
|
43 | - 'readable-value' => 'boolean ' . $value, |
|
44 | - ], |
|
45 | - 'false' => [ |
|
46 | - 'value' => false, |
|
47 | - 'readable-value' => 'boolean ' . $value, |
|
48 | - ], |
|
49 | - default => throw new \InvalidArgumentException('Unable to parse value as boolean'), |
|
50 | - }; |
|
37 | + case 'boolean': |
|
38 | + case 'bool': |
|
39 | + $value = strtolower($value); |
|
40 | + return match ($value) { |
|
41 | + 'true' => [ |
|
42 | + 'value' => true, |
|
43 | + 'readable-value' => 'boolean ' . $value, |
|
44 | + ], |
|
45 | + 'false' => [ |
|
46 | + 'value' => false, |
|
47 | + 'readable-value' => 'boolean ' . $value, |
|
48 | + ], |
|
49 | + default => throw new \InvalidArgumentException('Unable to parse value as boolean'), |
|
50 | + }; |
|
51 | 51 | |
52 | - case 'null': |
|
53 | - return [ |
|
54 | - 'value' => null, |
|
55 | - 'readable-value' => 'null', |
|
56 | - ]; |
|
52 | + case 'null': |
|
53 | + return [ |
|
54 | + 'value' => null, |
|
55 | + 'readable-value' => 'null', |
|
56 | + ]; |
|
57 | 57 | |
58 | - case 'string': |
|
59 | - $value = (string)$value; |
|
60 | - return [ |
|
61 | - 'value' => $value, |
|
62 | - 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
63 | - ]; |
|
58 | + case 'string': |
|
59 | + $value = (string)$value; |
|
60 | + return [ |
|
61 | + 'value' => $value, |
|
62 | + 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
63 | + ]; |
|
64 | 64 | |
65 | - case 'json': |
|
66 | - $value = json_decode($value, true); |
|
67 | - return [ |
|
68 | - 'value' => $value, |
|
69 | - 'readable-value' => 'json ' . json_encode($value), |
|
70 | - ]; |
|
65 | + case 'json': |
|
66 | + $value = json_decode($value, true); |
|
67 | + return [ |
|
68 | + 'value' => $value, |
|
69 | + 'readable-value' => 'json ' . json_encode($value), |
|
70 | + ]; |
|
71 | 71 | |
72 | - default: |
|
73 | - throw new \InvalidArgumentException('Invalid type'); |
|
74 | - } |
|
75 | - } |
|
72 | + default: |
|
73 | + throw new \InvalidArgumentException('Invalid type'); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | throw new \InvalidArgumentException('Non-numeric value specified'); |
21 | 21 | } |
22 | 22 | return [ |
23 | - 'value' => (int)$value, |
|
24 | - 'readable-value' => 'integer ' . (int)$value, |
|
23 | + 'value' => (int) $value, |
|
24 | + 'readable-value' => 'integer '.(int) $value, |
|
25 | 25 | ]; |
26 | 26 | |
27 | 27 | case 'double': |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | throw new \InvalidArgumentException('Non-numeric value specified'); |
31 | 31 | } |
32 | 32 | return [ |
33 | - 'value' => (float)$value, |
|
34 | - 'readable-value' => 'double ' . (float)$value, |
|
33 | + 'value' => (float) $value, |
|
34 | + 'readable-value' => 'double '.(float) $value, |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | case 'boolean': |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | return match ($value) { |
41 | 41 | 'true' => [ |
42 | 42 | 'value' => true, |
43 | - 'readable-value' => 'boolean ' . $value, |
|
43 | + 'readable-value' => 'boolean '.$value, |
|
44 | 44 | ], |
45 | 45 | 'false' => [ |
46 | 46 | 'value' => false, |
47 | - 'readable-value' => 'boolean ' . $value, |
|
47 | + 'readable-value' => 'boolean '.$value, |
|
48 | 48 | ], |
49 | 49 | default => throw new \InvalidArgumentException('Unable to parse value as boolean'), |
50 | 50 | }; |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | ]; |
57 | 57 | |
58 | 58 | case 'string': |
59 | - $value = (string)$value; |
|
59 | + $value = (string) $value; |
|
60 | 60 | return [ |
61 | 61 | 'value' => $value, |
62 | - 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
62 | + 'readable-value' => ($value === '') ? 'empty string' : 'string '.$value, |
|
63 | 63 | ]; |
64 | 64 | |
65 | 65 | case 'json': |
66 | 66 | $value = json_decode($value, true); |
67 | 67 | return [ |
68 | 68 | 'value' => $value, |
69 | - 'readable-value' => 'json ' . json_encode($value), |
|
69 | + 'readable-value' => 'json '.json_encode($value), |
|
70 | 70 | ]; |
71 | 71 | |
72 | 72 | default: |