Total Complexity | 7 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
8 | class InlineInputSource implements InputSourceInterface |
||
9 | { |
||
10 | protected string $data; |
||
11 | |||
12 | /** |
||
13 | * InlineInputSource constructor. |
||
14 | * |
||
15 | * @param string $data |
||
16 | */ |
||
17 | 1 | public function __construct(string $data) |
|
18 | { |
||
19 | 1 | $this->data = $data; |
|
20 | } |
||
21 | |||
22 | /** |
||
23 | * @return array<string,string> |
||
24 | */ |
||
25 | 1 | public function toArray(): array |
|
30 | ]; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Helper method to convert array to a json string. |
||
35 | * |
||
36 | * @param array<array<string|int|float|bool|null|array<mixed>>> $data |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 1 | public static function dataToJson(array $data): string |
|
41 | { |
||
42 | 1 | return implode("\n", array_map(fn($elem) => json_encode($elem), $data)); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Helper method to convert an array to a csv string. |
||
47 | * |
||
48 | * @param array<array<string|int|float|bool|null>> $data |
||
49 | * @param string $separator |
||
50 | * @param string $enclosure |
||
51 | * @param string $escape |
||
52 | * |
||
53 | * @return string |
||
54 | * @throws \Exception |
||
55 | */ |
||
56 | 1 | public static function dataToCsv( |
|
78 | } |
||
79 | } |