@@ -23,47 +23,47 @@ |
||
| 23 | 23 | use function strpos; |
| 24 | 24 | class NDJsonSerializer implements SerializerInterface |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * The available $options are: |
|
| 28 | - * 'remove_null' => (bool) enable/disable the removing of |
|
| 29 | - * null values (default is true) |
|
| 30 | - * |
|
| 31 | - * @param array $data |
|
| 32 | - */ |
|
| 33 | - public static function serialize($data, array $options = []) : string |
|
| 34 | - { |
|
| 35 | - $result = ''; |
|
| 36 | - foreach ($data as $row) { |
|
| 37 | - if (empty($row)) { |
|
| 38 | - $result .= "{}\n"; |
|
| 39 | - continue; |
|
| 40 | - } |
|
| 41 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
| 42 | - } |
|
| 43 | - return $result; |
|
| 44 | - } |
|
| 45 | - /** |
|
| 46 | - * The available options are: |
|
| 47 | - * 'type' => (string) specify if the array result should contain object |
|
| 48 | - * or array (default is array) |
|
| 49 | - * |
|
| 50 | - * @inheritdoc |
|
| 51 | - */ |
|
| 52 | - public static function unserialize(string $data, array $options = []) |
|
| 53 | - { |
|
| 54 | - $array = explode(strpos($data, "\r\n") !== \false ? "\r\n" : "\n", $data); |
|
| 55 | - $result = []; |
|
| 56 | - foreach ($array as $json) { |
|
| 57 | - if (empty($json)) { |
|
| 58 | - continue; |
|
| 59 | - } |
|
| 60 | - try { |
|
| 61 | - $result[] = JsonSerializer::unserialize($json, $options); |
|
| 62 | - } catch (JsonException $e) { |
|
| 63 | - throw new InvalidJsonException(sprintf("Not a valid NDJson: %s", $e->getMessage())); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $type = $options['type'] ?? 'array'; |
|
| 67 | - return $type === 'array' ? $result : new ArrayObject($result); |
|
| 68 | - } |
|
| 26 | + /** |
|
| 27 | + * The available $options are: |
|
| 28 | + * 'remove_null' => (bool) enable/disable the removing of |
|
| 29 | + * null values (default is true) |
|
| 30 | + * |
|
| 31 | + * @param array $data |
|
| 32 | + */ |
|
| 33 | + public static function serialize($data, array $options = []) : string |
|
| 34 | + { |
|
| 35 | + $result = ''; |
|
| 36 | + foreach ($data as $row) { |
|
| 37 | + if (empty($row)) { |
|
| 38 | + $result .= "{}\n"; |
|
| 39 | + continue; |
|
| 40 | + } |
|
| 41 | + $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
| 42 | + } |
|
| 43 | + return $result; |
|
| 44 | + } |
|
| 45 | + /** |
|
| 46 | + * The available options are: |
|
| 47 | + * 'type' => (string) specify if the array result should contain object |
|
| 48 | + * or array (default is array) |
|
| 49 | + * |
|
| 50 | + * @inheritdoc |
|
| 51 | + */ |
|
| 52 | + public static function unserialize(string $data, array $options = []) |
|
| 53 | + { |
|
| 54 | + $array = explode(strpos($data, "\r\n") !== \false ? "\r\n" : "\n", $data); |
|
| 55 | + $result = []; |
|
| 56 | + foreach ($array as $json) { |
|
| 57 | + if (empty($json)) { |
|
| 58 | + continue; |
|
| 59 | + } |
|
| 60 | + try { |
|
| 61 | + $result[] = JsonSerializer::unserialize($json, $options); |
|
| 62 | + } catch (JsonException $e) { |
|
| 63 | + throw new InvalidJsonException(sprintf("Not a valid NDJson: %s", $e->getMessage())); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $type = $options['type'] ?? 'array'; |
|
| 67 | + return $type === 'array' ? $result : new ArrayObject($result); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use ArrayObject; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $result .= "{}\n"; |
| 39 | 39 | continue; |
| 40 | 40 | } |
| 41 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
| 41 | + $result .= JsonSerializer::serialize($row, $options)."\n"; |
|
| 42 | 42 | } |
| 43 | 43 | return $result; |
| 44 | 44 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | use function json_decode; |
| 22 | 22 | use function sprintf; |
| 23 | 23 | use function strpos; |
| 24 | -class NDJsonSerializer implements SerializerInterface |
|
| 25 | -{ |
|
| 24 | +class NDJsonSerializer implements SerializerInterface { |
|
| 26 | 25 | /** |
| 27 | 26 | * The available $options are: |
| 28 | 27 | * 'remove_null' => (bool) enable/disable the removing of |
@@ -21,30 +21,30 @@ |
||
| 21 | 21 | use function sprintf; |
| 22 | 22 | class Utility |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Remove null values form array or object |
|
| 26 | - * |
|
| 27 | - * @param mixed $data |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public static function removeNullValue(&$data) : void |
|
| 31 | - { |
|
| 32 | - if (!is_object($data) && !is_array($data)) { |
|
| 33 | - throw new InvalidArgumentException(sprintf("The parameter %s must be an object or array", var_export($data, \true))); |
|
| 34 | - } |
|
| 35 | - /** @phpstan-ignore-next-line */ |
|
| 36 | - foreach ($data as $property => &$value) { |
|
| 37 | - if (is_object($value) || is_array($value)) { |
|
| 38 | - self::removeNullValue($value); |
|
| 39 | - } |
|
| 40 | - if (null === $value) { |
|
| 41 | - if (is_array($data)) { |
|
| 42 | - unset($data[$property]); |
|
| 43 | - } |
|
| 44 | - if (is_object($data)) { |
|
| 45 | - unset($data->{$property}); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 24 | + /** |
|
| 25 | + * Remove null values form array or object |
|
| 26 | + * |
|
| 27 | + * @param mixed $data |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public static function removeNullValue(&$data) : void |
|
| 31 | + { |
|
| 32 | + if (!is_object($data) && !is_array($data)) { |
|
| 33 | + throw new InvalidArgumentException(sprintf("The parameter %s must be an object or array", var_export($data, \true))); |
|
| 34 | + } |
|
| 35 | + /** @phpstan-ignore-next-line */ |
|
| 36 | + foreach ($data as $property => &$value) { |
|
| 37 | + if (is_object($value) || is_array($value)) { |
|
| 38 | + self::removeNullValue($value); |
|
| 39 | + } |
|
| 40 | + if (null === $value) { |
|
| 41 | + if (is_array($data)) { |
|
| 42 | + unset($data[$property]); |
|
| 43 | + } |
|
| 44 | + if (is_object($data)) { |
|
| 45 | + unset($data->{$property}); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArgumentException; |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | use function is_object; |
| 20 | 20 | use function var_export; |
| 21 | 21 | use function sprintf; |
| 22 | -class Utility |
|
| 23 | -{ |
|
| 22 | +class Utility { |
|
| 24 | 23 | /** |
| 25 | 24 | * Remove null values form array or object |
| 26 | 25 | * |
@@ -16,16 +16,16 @@ |
||
| 16 | 16 | |
| 17 | 17 | interface SerializerInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @param mixed $data |
|
| 21 | - * @param array $options |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - public static function serialize($data, array $options = []) : string; |
|
| 25 | - /** |
|
| 26 | - * @param string $data |
|
| 27 | - * @param array $options |
|
| 28 | - * @return mixed |
|
| 29 | - */ |
|
| 30 | - public static function unserialize(string $data, array $options = []); |
|
| 19 | + /** |
|
| 20 | + * @param mixed $data |
|
| 21 | + * @param array $options |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + public static function serialize($data, array $options = []) : string; |
|
| 25 | + /** |
|
| 26 | + * @param string $data |
|
| 27 | + * @param array $options |
|
| 28 | + * @return mixed |
|
| 29 | + */ |
|
| 30 | + public static function unserialize(string $data, array $options = []); |
|
| 31 | 31 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | interface SerializerInterface |
@@ -14,8 +14,7 @@ |
||
| 14 | 14 | declare (strict_types=1); |
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | -interface SerializerInterface |
|
| 18 | -{ |
|
| 17 | +interface SerializerInterface { |
|
| 19 | 18 | /** |
| 20 | 19 | * @param mixed $data |
| 21 | 20 | * @param array $options |
@@ -22,36 +22,36 @@ |
||
| 22 | 22 | use function substr; |
| 23 | 23 | class CsvSerializer implements SerializerInterface |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @inheritdoc |
|
| 27 | - * |
|
| 28 | - * @throws InvalidIterableException |
|
| 29 | - */ |
|
| 30 | - public static function serialize($data, array $options = []) : string |
|
| 31 | - { |
|
| 32 | - if (!is_iterable($data)) { |
|
| 33 | - throw new InvalidIterableException(sprintf("The parameter %s is not iterable", \serialize($data))); |
|
| 34 | - } |
|
| 35 | - $result = ''; |
|
| 36 | - foreach ($data as $row) { |
|
| 37 | - if (\is_array($row) || \is_object($row)) { |
|
| 38 | - $result .= \implode(',', (array) $row); |
|
| 39 | - } else { |
|
| 40 | - $result .= (string) $row; |
|
| 41 | - } |
|
| 42 | - $result .= "\n"; |
|
| 43 | - } |
|
| 44 | - return empty($result) ? $result : substr($result, 0, -1); |
|
| 45 | - } |
|
| 46 | - /** |
|
| 47 | - * @return array |
|
| 48 | - */ |
|
| 49 | - public static function unserialize(string $data, array $options = []) : array |
|
| 50 | - { |
|
| 51 | - $result = []; |
|
| 52 | - foreach (explode("\n", $data) as $row) { |
|
| 53 | - $result[] = str_getcsv($row); |
|
| 54 | - } |
|
| 55 | - return $result; |
|
| 56 | - } |
|
| 25 | + /** |
|
| 26 | + * @inheritdoc |
|
| 27 | + * |
|
| 28 | + * @throws InvalidIterableException |
|
| 29 | + */ |
|
| 30 | + public static function serialize($data, array $options = []) : string |
|
| 31 | + { |
|
| 32 | + if (!is_iterable($data)) { |
|
| 33 | + throw new InvalidIterableException(sprintf("The parameter %s is not iterable", \serialize($data))); |
|
| 34 | + } |
|
| 35 | + $result = ''; |
|
| 36 | + foreach ($data as $row) { |
|
| 37 | + if (\is_array($row) || \is_object($row)) { |
|
| 38 | + $result .= \implode(',', (array) $row); |
|
| 39 | + } else { |
|
| 40 | + $result .= (string) $row; |
|
| 41 | + } |
|
| 42 | + $result .= "\n"; |
|
| 43 | + } |
|
| 44 | + return empty($result) ? $result : substr($result, 0, -1); |
|
| 45 | + } |
|
| 46 | + /** |
|
| 47 | + * @return array |
|
| 48 | + */ |
|
| 49 | + public static function unserialize(string $data, array $options = []) : array |
|
| 50 | + { |
|
| 51 | + $result = []; |
|
| 52 | + foreach (explode("\n", $data) as $row) { |
|
| 53 | + $result[] = str_getcsv($row); |
|
| 54 | + } |
|
| 55 | + return $result; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidIterableException; |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | $result = ''; |
| 36 | 36 | foreach ($data as $row) { |
| 37 | 37 | if (\is_array($row) || \is_object($row)) { |
| 38 | - $result .= \implode(',', (array) $row); |
|
| 38 | + $result .= \implode(',', (array)$row); |
|
| 39 | 39 | } else { |
| 40 | - $result .= (string) $row; |
|
| 40 | + $result .= (string)$row; |
|
| 41 | 41 | } |
| 42 | 42 | $result .= "\n"; |
| 43 | 43 | } |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | use function sprintf; |
| 21 | 21 | use function str_getcsv; |
| 22 | 22 | use function substr; |
| 23 | -class CsvSerializer implements SerializerInterface |
|
| 24 | -{ |
|
| 23 | +class CsvSerializer implements SerializerInterface { |
|
| 25 | 24 | /** |
| 26 | 25 | * @inheritdoc |
| 27 | 26 | * |
@@ -23,48 +23,48 @@ |
||
| 23 | 23 | use function sprintf; |
| 24 | 24 | class JsonSerializer implements SerializerInterface |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * The available $options are: |
|
| 28 | - * 'remove_null' => (bool) enable/disable the removing of |
|
| 29 | - * null values (default is true) |
|
| 30 | - * |
|
| 31 | - * @param mixed $data |
|
| 32 | - */ |
|
| 33 | - public static function serialize($data, array $options = []) : string |
|
| 34 | - { |
|
| 35 | - if (empty($data)) { |
|
| 36 | - return '{}'; |
|
| 37 | - } |
|
| 38 | - if (\is_string($data)) { |
|
| 39 | - return $data; |
|
| 40 | - } |
|
| 41 | - try { |
|
| 42 | - $removeNull = $options['remove_null'] ?? \true; |
|
| 43 | - if ($removeNull) { |
|
| 44 | - Utility::removeNullValue($data); |
|
| 45 | - } |
|
| 46 | - return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
| 47 | - } catch (JsonException $e) { |
|
| 48 | - throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - /** |
|
| 52 | - * The available options are: |
|
| 53 | - * 'type' => (string) specify if the output should be an array |
|
| 54 | - * or an object (default is array) |
|
| 55 | - * |
|
| 56 | - * @inheritdoc |
|
| 57 | - */ |
|
| 58 | - public static function unserialize(string $data, array $options = []) |
|
| 59 | - { |
|
| 60 | - try { |
|
| 61 | - $type = $options['type'] ?? 'array'; |
|
| 62 | - if (!in_array($type, ['object', 'array'])) { |
|
| 63 | - throw new UndefinedPropertyException("The unserialize 'type' option must be object or array"); |
|
| 64 | - } |
|
| 65 | - return json_decode($data, $type === 'array', 512, \JSON_THROW_ON_ERROR); |
|
| 66 | - } catch (JsonException $e) { |
|
| 67 | - throw new InvalidJsonException(sprintf("Not a valid Json: %s", $e->getMessage())); |
|
| 68 | - } |
|
| 69 | - } |
|
| 26 | + /** |
|
| 27 | + * The available $options are: |
|
| 28 | + * 'remove_null' => (bool) enable/disable the removing of |
|
| 29 | + * null values (default is true) |
|
| 30 | + * |
|
| 31 | + * @param mixed $data |
|
| 32 | + */ |
|
| 33 | + public static function serialize($data, array $options = []) : string |
|
| 34 | + { |
|
| 35 | + if (empty($data)) { |
|
| 36 | + return '{}'; |
|
| 37 | + } |
|
| 38 | + if (\is_string($data)) { |
|
| 39 | + return $data; |
|
| 40 | + } |
|
| 41 | + try { |
|
| 42 | + $removeNull = $options['remove_null'] ?? \true; |
|
| 43 | + if ($removeNull) { |
|
| 44 | + Utility::removeNullValue($data); |
|
| 45 | + } |
|
| 46 | + return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
| 47 | + } catch (JsonException $e) { |
|
| 48 | + throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + /** |
|
| 52 | + * The available options are: |
|
| 53 | + * 'type' => (string) specify if the output should be an array |
|
| 54 | + * or an object (default is array) |
|
| 55 | + * |
|
| 56 | + * @inheritdoc |
|
| 57 | + */ |
|
| 58 | + public static function unserialize(string $data, array $options = []) |
|
| 59 | + { |
|
| 60 | + try { |
|
| 61 | + $type = $options['type'] ?? 'array'; |
|
| 62 | + if (!in_array($type, ['object', 'array'])) { |
|
| 63 | + throw new UndefinedPropertyException("The unserialize 'type' option must be object or array"); |
|
| 64 | + } |
|
| 65 | + return json_decode($data, $type === 'array', 512, \JSON_THROW_ON_ERROR); |
|
| 66 | + } catch (JsonException $e) { |
|
| 67 | + throw new InvalidJsonException(sprintf("Not a valid Json: %s", $e->getMessage())); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidJsonException; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | if ($removeNull) { |
| 44 | 44 | Utility::removeNullValue($data); |
| 45 | 45 | } |
| 46 | - return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
| 46 | + return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION +\JSON_INVALID_UTF8_SUBSTITUTE +\JSON_THROW_ON_ERROR); |
|
| 47 | 47 | } catch (JsonException $e) { |
| 48 | 48 | throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
| 49 | 49 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | use function json_decode; |
| 22 | 22 | use function json_encode; |
| 23 | 23 | use function sprintf; |
| 24 | -class JsonSerializer implements SerializerInterface |
|
| 25 | -{ |
|
| 24 | +class JsonSerializer implements SerializerInterface { |
|
| 26 | 25 | /** |
| 27 | 26 | * The available $options are: |
| 28 | 27 | * 'remove_null' => (bool) enable/disable the removing of |
@@ -18,21 +18,21 @@ |
||
| 18 | 18 | use function serialize; |
| 19 | 19 | class TextSerializer implements SerializerInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @throws SerializeException |
|
| 23 | - */ |
|
| 24 | - public static function serialize($data, array $options = []) : string |
|
| 25 | - { |
|
| 26 | - if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
|
| 27 | - return (string) $data; |
|
| 28 | - } |
|
| 29 | - throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
|
| 30 | - } |
|
| 31 | - /** |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public static function unserialize(string $data, array $options = []) : string |
|
| 35 | - { |
|
| 36 | - return $data; |
|
| 37 | - } |
|
| 21 | + /** |
|
| 22 | + * @throws SerializeException |
|
| 23 | + */ |
|
| 24 | + public static function serialize($data, array $options = []) : string |
|
| 25 | + { |
|
| 26 | + if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
|
| 27 | + return (string) $data; |
|
| 28 | + } |
|
| 29 | + throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
|
| 30 | + } |
|
| 31 | + /** |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public static function unserialize(string $data, array $options = []) : string |
|
| 35 | + { |
|
| 36 | + return $data; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\SerializeException; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public static function serialize($data, array $options = []) : string |
| 25 | 25 | { |
| 26 | 26 | if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
| 27 | - return (string) $data; |
|
| 27 | + return (string)$data; |
|
| 28 | 28 | } |
| 29 | 29 | throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
| 30 | 30 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\SerializeException; |
| 18 | 18 | use function serialize; |
| 19 | -class TextSerializer implements SerializerInterface |
|
| 20 | -{ |
|
| 19 | +class TextSerializer implements SerializerInterface { |
|
| 21 | 20 | /** |
| 22 | 21 | * @throws SerializeException |
| 23 | 22 | */ |
@@ -23,25 +23,25 @@ |
||
| 23 | 23 | use function sprintf; |
| 24 | 24 | class XmlSerializer implements SerializerInterface |
| 25 | 25 | { |
| 26 | - public static function serialize($data, array $options = []) : string |
|
| 27 | - { |
|
| 28 | - if ($data instanceof SimpleXMLElement) { |
|
| 29 | - $xml = $data->asXML(); |
|
| 30 | - return \false === $xml ? '' : $xml; |
|
| 31 | - } |
|
| 32 | - throw new InvalidXmlException(sprintf("Not a valid SimpleXMLElement: %s", serialize($data))); |
|
| 33 | - } |
|
| 34 | - /** |
|
| 35 | - * @return SimpleXMLElement |
|
| 36 | - */ |
|
| 37 | - public static function unserialize(string $data, array $options = []) : SimpleXMLElement |
|
| 38 | - { |
|
| 39 | - $result = simplexml_load_string($data); |
|
| 40 | - if (\false === $result) { |
|
| 41 | - $errors = libxml_get_errors(); |
|
| 42 | - libxml_clear_errors(); |
|
| 43 | - throw new InvalidXmlException(sprintf("Not a valid XML: %s", serialize($errors))); |
|
| 44 | - } |
|
| 45 | - return $result; |
|
| 46 | - } |
|
| 26 | + public static function serialize($data, array $options = []) : string |
|
| 27 | + { |
|
| 28 | + if ($data instanceof SimpleXMLElement) { |
|
| 29 | + $xml = $data->asXML(); |
|
| 30 | + return \false === $xml ? '' : $xml; |
|
| 31 | + } |
|
| 32 | + throw new InvalidXmlException(sprintf("Not a valid SimpleXMLElement: %s", serialize($data))); |
|
| 33 | + } |
|
| 34 | + /** |
|
| 35 | + * @return SimpleXMLElement |
|
| 36 | + */ |
|
| 37 | + public static function unserialize(string $data, array $options = []) : SimpleXMLElement |
|
| 38 | + { |
|
| 39 | + $result = simplexml_load_string($data); |
|
| 40 | + if (\false === $result) { |
|
| 41 | + $errors = libxml_get_errors(); |
|
| 42 | + libxml_clear_errors(); |
|
| 43 | + throw new InvalidXmlException(sprintf("Not a valid XML: %s", serialize($errors))); |
|
| 44 | + } |
|
| 45 | + return $result; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidXmlException; |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | use function serialize; |
| 22 | 22 | use function simplexml_load_string; |
| 23 | 23 | use function sprintf; |
| 24 | -class XmlSerializer implements SerializerInterface |
|
| 25 | -{ |
|
| 24 | +class XmlSerializer implements SerializerInterface { |
|
| 26 | 25 | public static function serialize($data, array $options = []) : string |
| 27 | 26 | { |
| 28 | 27 | if ($data instanceof SimpleXMLElement) { |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |
@@ -15,6 +15,5 @@ |
||
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |
| 18 | -class InvalidArrayException extends RuntimeException implements TransportException |
|
| 19 | -{ |
|
| 18 | +class InvalidArrayException extends RuntimeException implements TransportException { |
|
| 20 | 19 | } |
@@ -15,6 +15,5 @@ |
||
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |
| 18 | -class InvalidArgumentException extends RuntimeException implements TransportException |
|
| 19 | -{ |
|
| 18 | +class InvalidArgumentException extends RuntimeException implements TransportException { |
|
| 20 | 19 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |