@@ -24,39 +24,39 @@ |
||
24 | 24 | |
25 | 25 | class CsvSerializer implements SerializerInterface |
26 | 26 | { |
27 | - /** |
|
28 | - * @inheritdoc |
|
29 | - * |
|
30 | - * @throws InvalidIterableException |
|
31 | - */ |
|
32 | - public static function serialize($data, array $options = []): string |
|
33 | - { |
|
34 | - if (!is_iterable($data)) { |
|
35 | - throw new InvalidIterableException( |
|
36 | - sprintf("The parameter %s is not iterable", serialize($data)) |
|
37 | - ); |
|
38 | - } |
|
39 | - $result = ''; |
|
40 | - foreach ($data as $row) { |
|
41 | - if (is_array($row) || is_object($row)) { |
|
42 | - $result .= implode(',', (array) $row); |
|
43 | - } else { |
|
44 | - $result .= (string) $row; |
|
45 | - } |
|
46 | - $result .= "\n"; |
|
47 | - } |
|
48 | - return empty($result) ? $result : substr($result, 0, -1); |
|
49 | - } |
|
27 | + /** |
|
28 | + * @inheritdoc |
|
29 | + * |
|
30 | + * @throws InvalidIterableException |
|
31 | + */ |
|
32 | + public static function serialize($data, array $options = []): string |
|
33 | + { |
|
34 | + if (!is_iterable($data)) { |
|
35 | + throw new InvalidIterableException( |
|
36 | + sprintf("The parameter %s is not iterable", serialize($data)) |
|
37 | + ); |
|
38 | + } |
|
39 | + $result = ''; |
|
40 | + foreach ($data as $row) { |
|
41 | + if (is_array($row) || is_object($row)) { |
|
42 | + $result .= implode(',', (array) $row); |
|
43 | + } else { |
|
44 | + $result .= (string) $row; |
|
45 | + } |
|
46 | + $result .= "\n"; |
|
47 | + } |
|
48 | + return empty($result) ? $result : substr($result, 0, -1); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public static function unserialize(string $data, array $options = []): array |
|
55 | - { |
|
56 | - $result = []; |
|
57 | - foreach (explode("\n", $data) as $row) { |
|
58 | - $result[] = str_getcsv($row); |
|
59 | - } |
|
60 | - return $result; |
|
61 | - } |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public static function unserialize(string $data, array $options = []): array |
|
55 | + { |
|
56 | + $result = []; |
|
57 | + foreach (explode("\n", $data) as $row) { |
|
58 | + $result[] = str_getcsv($row); |
|
59 | + } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | \ No newline at end of file |
@@ -39,9 +39,9 @@ |
||
39 | 39 | $result = ''; |
40 | 40 | foreach ($data as $row) { |
41 | 41 | if (is_array($row) || is_object($row)) { |
42 | - $result .= implode(',', (array) $row); |
|
42 | + $result .= implode(',', (array)$row); |
|
43 | 43 | } else { |
44 | - $result .= (string) $row; |
|
44 | + $result .= (string)$row; |
|
45 | 45 | } |
46 | 46 | $result .= "\n"; |
47 | 47 | } |
@@ -22,8 +22,7 @@ |
||
22 | 22 | use function str_getcsv; |
23 | 23 | use function substr; |
24 | 24 | |
25 | -class CsvSerializer implements SerializerInterface |
|
26 | -{ |
|
25 | +class CsvSerializer implements SerializerInterface { |
|
27 | 26 | /** |
28 | 27 | * @inheritdoc |
29 | 28 | * |
@@ -23,32 +23,32 @@ |
||
23 | 23 | |
24 | 24 | class Utility |
25 | 25 | { |
26 | - /** |
|
27 | - * Remove null values form array or object |
|
28 | - * |
|
29 | - * @param mixed $data |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public static function removeNullValue(&$data): void |
|
33 | - { |
|
34 | - if (!is_object($data) && !is_array($data)) { |
|
35 | - throw new InvalidArgumentException( |
|
36 | - sprintf("The parameter %s must be an object or array", var_export($data, true)) |
|
37 | - ); |
|
38 | - } |
|
39 | - /** @phpstan-ignore-next-line */ |
|
40 | - foreach ($data as $property => &$value) { |
|
41 | - if (is_object($value) || is_array($value)) { |
|
42 | - self::removeNullValue($value); |
|
43 | - } |
|
44 | - if (null === $value) { |
|
45 | - if (is_array($data)) { |
|
46 | - unset($data[$property]); |
|
47 | - } |
|
48 | - if (is_object($data)) { |
|
49 | - unset($data->$property); |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
26 | + /** |
|
27 | + * Remove null values form array or object |
|
28 | + * |
|
29 | + * @param mixed $data |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public static function removeNullValue(&$data): void |
|
33 | + { |
|
34 | + if (!is_object($data) && !is_array($data)) { |
|
35 | + throw new InvalidArgumentException( |
|
36 | + sprintf("The parameter %s must be an object or array", var_export($data, true)) |
|
37 | + ); |
|
38 | + } |
|
39 | + /** @phpstan-ignore-next-line */ |
|
40 | + foreach ($data as $property => &$value) { |
|
41 | + if (is_object($value) || is_array($value)) { |
|
42 | + self::removeNullValue($value); |
|
43 | + } |
|
44 | + if (null === $value) { |
|
45 | + if (is_array($data)) { |
|
46 | + unset($data[$property]); |
|
47 | + } |
|
48 | + if (is_object($data)) { |
|
49 | + unset($data->$property); |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | \ No newline at end of file |
@@ -21,8 +21,7 @@ |
||
21 | 21 | use function var_export; |
22 | 22 | use function sprintf; |
23 | 23 | |
24 | -class Utility |
|
25 | -{ |
|
24 | +class Utility { |
|
26 | 25 | /** |
27 | 26 | * Remove null values form array or object |
28 | 27 | * |
@@ -25,51 +25,51 @@ |
||
25 | 25 | |
26 | 26 | class NDJsonSerializer implements SerializerInterface |
27 | 27 | { |
28 | - /** |
|
29 | - * The available $options are: |
|
30 | - * 'remove_null' => (bool) enable/disable the removing of |
|
31 | - * null values (default is true) |
|
32 | - * |
|
33 | - * @param array $data |
|
34 | - */ |
|
35 | - public static function serialize($data, array $options = []): string |
|
36 | - { |
|
37 | - $result = ''; |
|
38 | - foreach ($data as $row) { |
|
39 | - if (empty($row)) { |
|
40 | - $result .= "{}\n"; |
|
41 | - continue; |
|
42 | - } |
|
43 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
44 | - } |
|
45 | - return $result; |
|
46 | - } |
|
28 | + /** |
|
29 | + * The available $options are: |
|
30 | + * 'remove_null' => (bool) enable/disable the removing of |
|
31 | + * null values (default is true) |
|
32 | + * |
|
33 | + * @param array $data |
|
34 | + */ |
|
35 | + public static function serialize($data, array $options = []): string |
|
36 | + { |
|
37 | + $result = ''; |
|
38 | + foreach ($data as $row) { |
|
39 | + if (empty($row)) { |
|
40 | + $result .= "{}\n"; |
|
41 | + continue; |
|
42 | + } |
|
43 | + $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
44 | + } |
|
45 | + return $result; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * The available options are: |
|
50 | - * 'type' => (string) specify if the array result should contain object |
|
51 | - * or array (default is array) |
|
52 | - * |
|
53 | - * @inheritdoc |
|
54 | - */ |
|
55 | - public static function unserialize(string $data, array $options = []) |
|
56 | - { |
|
57 | - $array = explode(strpos($data, "\r\n") !== false ? "\r\n" : "\n", $data); |
|
58 | - $result = []; |
|
59 | - foreach ($array as $json) { |
|
60 | - if (empty($json)) { |
|
61 | - continue; |
|
62 | - } |
|
63 | - try { |
|
64 | - $result[] = JsonSerializer::unserialize($json, $options); |
|
65 | - } catch (JsonException $e) { |
|
66 | - throw new InvalidJsonException(sprintf( |
|
67 | - "Not a valid NDJson: %s", |
|
68 | - $e->getMessage() |
|
69 | - )); |
|
70 | - } |
|
71 | - } |
|
72 | - $type = $options['type'] ?? 'array'; |
|
73 | - return $type === 'array' ? $result : new ArrayObject($result); |
|
74 | - } |
|
48 | + /** |
|
49 | + * The available options are: |
|
50 | + * 'type' => (string) specify if the array result should contain object |
|
51 | + * or array (default is array) |
|
52 | + * |
|
53 | + * @inheritdoc |
|
54 | + */ |
|
55 | + public static function unserialize(string $data, array $options = []) |
|
56 | + { |
|
57 | + $array = explode(strpos($data, "\r\n") !== false ? "\r\n" : "\n", $data); |
|
58 | + $result = []; |
|
59 | + foreach ($array as $json) { |
|
60 | + if (empty($json)) { |
|
61 | + continue; |
|
62 | + } |
|
63 | + try { |
|
64 | + $result[] = JsonSerializer::unserialize($json, $options); |
|
65 | + } catch (JsonException $e) { |
|
66 | + throw new InvalidJsonException(sprintf( |
|
67 | + "Not a valid NDJson: %s", |
|
68 | + $e->getMessage() |
|
69 | + )); |
|
70 | + } |
|
71 | + } |
|
72 | + $type = $options['type'] ?? 'array'; |
|
73 | + return $type === 'array' ? $result : new ArrayObject($result); |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $result .= "{}\n"; |
41 | 41 | continue; |
42 | 42 | } |
43 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
43 | + $result .= JsonSerializer::serialize($row, $options)."\n"; |
|
44 | 44 | } |
45 | 45 | return $result; |
46 | 46 | } |
@@ -23,8 +23,7 @@ |
||
23 | 23 | use function sprintf; |
24 | 24 | use function strpos; |
25 | 25 | |
26 | -class NDJsonSerializer implements SerializerInterface |
|
27 | -{ |
|
26 | +class NDJsonSerializer implements SerializerInterface { |
|
28 | 27 | /** |
29 | 28 | * The available $options are: |
30 | 29 | * 'remove_null' => (bool) enable/disable the removing of |
@@ -18,8 +18,8 @@ |
||
18 | 18 | |
19 | 19 | interface OnSuccessInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @return mixed |
|
23 | - */ |
|
24 | - public function success(ResponseInterface $request, int $count); |
|
21 | + /** |
|
22 | + * @return mixed |
|
23 | + */ |
|
24 | + public function success(ResponseInterface $request, int $count); |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -16,8 +16,7 @@ |
||
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\ResponseInterface; |
18 | 18 | |
19 | -interface OnSuccessInterface |
|
20 | -{ |
|
19 | +interface OnSuccessInterface { |
|
21 | 20 | /** |
22 | 21 | * @return mixed |
23 | 22 | */ |
@@ -18,8 +18,8 @@ |
||
18 | 18 | |
19 | 19 | class OnSuccessDefault implements OnSuccessInterface |
20 | 20 | { |
21 | - public function success(ResponseInterface $response, int $count) |
|
22 | - { |
|
23 | - return $response; |
|
24 | - } |
|
21 | + public function success(ResponseInterface $response, int $count) |
|
22 | + { |
|
23 | + return $response; |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -16,8 +16,7 @@ |
||
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\ResponseInterface; |
18 | 18 | |
19 | -class OnSuccessDefault implements OnSuccessInterface |
|
20 | -{ |
|
19 | +class OnSuccessDefault implements OnSuccessInterface { |
|
21 | 20 | public function success(ResponseInterface $response, int $count) |
22 | 21 | { |
23 | 22 | return $response; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | class OnFailureDefault implements OnFailureInterface |
22 | 22 | { |
23 | - public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void |
|
24 | - { |
|
25 | - } |
|
23 | + public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void |
|
24 | + { |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -18,8 +18,7 @@ |
||
18 | 18 | use Exception; |
19 | 19 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestInterface; |
20 | 20 | |
21 | -class OnFailureDefault implements OnFailureInterface |
|
22 | -{ |
|
21 | +class OnFailureDefault implements OnFailureInterface { |
|
23 | 22 | public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void |
24 | 23 | { |
25 | 24 | } |
@@ -20,5 +20,5 @@ |
||
20 | 20 | |
21 | 21 | interface OnFailureInterface |
22 | 22 | { |
23 | - public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void; |
|
23 | + public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void; |
|
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -18,7 +18,6 @@ |
||
18 | 18 | use Exception; |
19 | 19 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestInterface; |
20 | 20 | |
21 | -interface OnFailureInterface |
|
22 | -{ |
|
21 | +interface OnFailureInterface { |
|
23 | 22 | public function failure(Exception $e, RequestInterface $request, int $count, Node $node = null): void; |
24 | 23 | } |
25 | 24 | \ No newline at end of file |
@@ -16,7 +16,6 @@ |
||
16 | 16 | |
17 | 17 | use RuntimeException as RootRuntimeException; |
18 | 18 | |
19 | -class RuntimeException extends RootRuntimeException implements TransportException |
|
20 | -{ |
|
19 | +class RuntimeException extends RootRuntimeException implements TransportException { |
|
21 | 20 | |
22 | 21 | } |
23 | 22 | \ No newline at end of file |
@@ -16,7 +16,6 @@ |
||
16 | 16 | |
17 | 17 | use RuntimeException; |
18 | 18 | |
19 | -class NoNodeAvailableException extends RuntimeException implements TransportException |
|
20 | -{ |
|
19 | +class NoNodeAvailableException extends RuntimeException implements TransportException { |
|
21 | 20 | |
22 | 21 | } |
23 | 22 | \ No newline at end of file |