Total Complexity | 8 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class StringToArrayParser extends AbstractStepTransformer |
||
6 | { |
||
7 | /** |
||
8 | * Steps that should be taken to transform the string from raw to end result. |
||
9 | * |
||
10 | * @return array |
||
11 | */ |
||
12 | protected static function getTransformerSteps() |
||
13 | { |
||
14 | return ['wrapInQuotes', 'wrapInArrayBrackets', 'decode']; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Replace `string with "quotes" inside` with `"string with \"quotes\" inside"` |
||
19 | * |
||
20 | * @param string $string |
||
21 | * @return string |
||
22 | */ |
||
23 | protected static function transformWrapInQuotes(string $content) { |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Replace `"string", "another"` with `["string", "another"]` |
||
37 | * |
||
38 | * @param string $content |
||
39 | * @return string |
||
40 | */ |
||
41 | protected static function transformWrapInArrayBrackets(string $content) { |
||
42 | // Once again, if it's already wrapped we do nothing and |
||
43 | // assume it's correct. |
||
44 | if(starts_with($content, '[') && ends_with($content, ']')) { |
||
45 | return $content; |
||
46 | } |
||
47 | |||
48 | return "[$content]"; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Decode JSON string into PHP array. |
||
53 | * |
||
54 | * @param $content |
||
55 | * |
||
56 | * @return array|null |
||
57 | */ |
||
58 | protected static function transformDecode(string $content) { |
||
60 | } |
||
61 | } |