Completed
Pull Request — master (#359)
by Maxence
41s
created
lib/Vendor/Elastic/Transport/Serializer/XmlSerializer.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -25,32 +25,32 @@
 block discarded – undo
25 25
 
26 26
 class XmlSerializer implements SerializerInterface
27 27
 {
28
-    public static function serialize($data, array $options = []): string
29
-    {
30
-        if ($data instanceof SimpleXMLElement) {
31
-            $xml = $data->asXML();
32
-            return false === $xml ? '' : $xml;
33
-        }
34
-        throw new InvalidXmlException(sprintf(
35
-            "Not a valid SimpleXMLElement: %s", 
36
-            serialize($data)
37
-        ));
38
-    }
28
+	public static function serialize($data, array $options = []): string
29
+	{
30
+		if ($data instanceof SimpleXMLElement) {
31
+			$xml = $data->asXML();
32
+			return false === $xml ? '' : $xml;
33
+		}
34
+		throw new InvalidXmlException(sprintf(
35
+			"Not a valid SimpleXMLElement: %s", 
36
+			serialize($data)
37
+		));
38
+	}
39 39
 
40
-    /**
41
-     * @return SimpleXMLElement
42
-     */
43
-    public static function unserialize(string $data, array $options = []): SimpleXMLElement
44
-    {
45
-        $result = simplexml_load_string($data);
46
-        if (false === $result) {
47
-            $errors = libxml_get_errors();
48
-            libxml_clear_errors();
49
-            throw new InvalidXmlException(sprintf(
50
-                "Not a valid XML: %s", 
51
-                serialize($errors)
52
-            ));
53
-        }
54
-        return $result;
55
-    }
40
+	/**
41
+	 * @return SimpleXMLElement
42
+	 */
43
+	public static function unserialize(string $data, array $options = []): SimpleXMLElement
44
+	{
45
+		$result = simplexml_load_string($data);
46
+		if (false === $result) {
47
+			$errors = libxml_get_errors();
48
+			libxml_clear_errors();
49
+			throw new InvalidXmlException(sprintf(
50
+				"Not a valid XML: %s", 
51
+				serialize($errors)
52
+			));
53
+		}
54
+		return $result;
55
+	}
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@
 block discarded – undo
23 23
 use function simplexml_load_string;
24 24
 use function sprintf;
25 25
 
26
-class XmlSerializer implements SerializerInterface
27
-{
26
+class XmlSerializer implements SerializerInterface {
28 27
     public static function serialize($data, array $options = []): string
29 28
     {
30 29
         if ($data instanceof SimpleXMLElement) {
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/JsonSerializer.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -26,54 +26,54 @@
 block discarded – undo
26 26
 class JsonSerializer implements SerializerInterface
27 27
 {
28 28
    /**
29
-     * The available $options are: 
30
-     * 'remove_null'  => (bool) enable/disable the removing of
31
-     *                   null values (default is true)
32
-     * 
33
-     * @param mixed $data
34
-     */
35
-    public static function serialize($data, array $options = []): string
36
-    {
37
-        if (empty($data)) {
38
-            return '{}';
39
-        }
40
-        if (is_string($data)) {
41
-            return $data;
42
-        }
43
-        try {
44
-            $removeNull = $options['remove_null'] ?? true;
45
-            if ($removeNull) {
46
-                Utility::removeNullValue($data);
47
-            }
48
-            return json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE + JSON_THROW_ON_ERROR);
49
-        } catch (JsonException $e) {
50
-            throw new InvalidJsonException(sprintf(
51
-                "I cannot serialize to Json: %s", 
52
-                $e->getMessage()
53
-            ));
54
-        }
55
-    }
29
+    * The available $options are: 
30
+    * 'remove_null'  => (bool) enable/disable the removing of
31
+    *                   null values (default is true)
32
+    * 
33
+    * @param mixed $data
34
+    */
35
+	public static function serialize($data, array $options = []): string
36
+	{
37
+		if (empty($data)) {
38
+			return '{}';
39
+		}
40
+		if (is_string($data)) {
41
+			return $data;
42
+		}
43
+		try {
44
+			$removeNull = $options['remove_null'] ?? true;
45
+			if ($removeNull) {
46
+				Utility::removeNullValue($data);
47
+			}
48
+			return json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE + JSON_THROW_ON_ERROR);
49
+		} catch (JsonException $e) {
50
+			throw new InvalidJsonException(sprintf(
51
+				"I cannot serialize to Json: %s", 
52
+				$e->getMessage()
53
+			));
54
+		}
55
+	}
56 56
 
57
-    /**
58
-     * The available options are:
59
-     * 'type' => (string) specify if the output should be an array
60
-     *           or an object (default is array)
61
-     * 
62
-     * @inheritdoc
63
-     */
64
-    public static function unserialize(string $data, array $options = [])
65
-    {
66
-        try {
67
-            $type = $options['type'] ?? 'array';
68
-            if (!in_array($type, ['object', 'array'])) {
69
-                throw new UndefinedPropertyException("The unserialize 'type' option must be object or array");
70
-            }
71
-            return json_decode($data, $type === 'array', 512, JSON_THROW_ON_ERROR);
72
-        } catch (JsonException $e) {
73
-            throw new InvalidJsonException(sprintf(
74
-                "Not a valid Json: %s", 
75
-                $e->getMessage()
76
-            ));
77
-        }
78
-    }
57
+	/**
58
+	 * The available options are:
59
+	 * 'type' => (string) specify if the output should be an array
60
+	 *           or an object (default is array)
61
+	 * 
62
+	 * @inheritdoc
63
+	 */
64
+	public static function unserialize(string $data, array $options = [])
65
+	{
66
+		try {
67
+			$type = $options['type'] ?? 'array';
68
+			if (!in_array($type, ['object', 'array'])) {
69
+				throw new UndefinedPropertyException("The unserialize 'type' option must be object or array");
70
+			}
71
+			return json_decode($data, $type === 'array', 512, JSON_THROW_ON_ERROR);
72
+		} catch (JsonException $e) {
73
+			throw new InvalidJsonException(sprintf(
74
+				"Not a valid Json: %s", 
75
+				$e->getMessage()
76
+			));
77
+		}
78
+	}
79 79
 }
80 80
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@
 block discarded – undo
23 23
 use function json_encode;
24 24
 use function sprintf;
25 25
 
26
-class JsonSerializer implements SerializerInterface
27
-{
26
+class JsonSerializer implements SerializerInterface {
28 27
    /**
29 28
      * The available $options are: 
30 29
      * 'remove_null'  => (bool) enable/disable the removing of
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/TextSerializer.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@
 block discarded – undo
20 20
 
21 21
 class TextSerializer implements SerializerInterface
22 22
 {
23
-    /**
24
-     * @throws SerializeException
25
-     */
26
-    public static function serialize($data, array $options = []): string
27
-    {
28
-        if (is_string($data) || is_numeric($data) || (is_object($data) && method_exists($data, '__toString'))) {
29
-            return (string) $data;
30
-        }
31
-        throw new SerializeException(
32
-            sprintf("I cannot serialize %s in a text", serialize($data))
33
-        );
34
-    }
23
+	/**
24
+	 * @throws SerializeException
25
+	 */
26
+	public static function serialize($data, array $options = []): string
27
+	{
28
+		if (is_string($data) || is_numeric($data) || (is_object($data) && method_exists($data, '__toString'))) {
29
+			return (string) $data;
30
+		}
31
+		throw new SerializeException(
32
+			sprintf("I cannot serialize %s in a text", serialize($data))
33
+		);
34
+	}
35 35
 
36
-    /**
37
-     * @return string
38
-     */
39
-    public static function unserialize(string $data, array $options = []): string
40
-    {
41
-        return $data;
42
-    }
36
+	/**
37
+	 * @return string
38
+	 */
39
+	public static function unserialize(string $data, array $options = []): string
40
+	{
41
+		return $data;
42
+	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
     public static function serialize($data, array $options = []): string
27 27
     {
28 28
         if (is_string($data) || is_numeric($data) || (is_object($data) && method_exists($data, '__toString'))) {
29
-            return (string) $data;
29
+            return (string)$data;
30 30
         }
31 31
         throw new SerializeException(
32 32
             sprintf("I cannot serialize %s in a text", serialize($data))
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@
 block discarded – undo
18 18
 
19 19
 use function serialize;
20 20
 
21
-class TextSerializer implements SerializerInterface
22
-{
21
+class TextSerializer implements SerializerInterface {
23 22
     /**
24 23
      * @throws SerializeException
25 24
      */
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/SerializerInterface.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@
 block discarded – undo
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;
19
+	/**
20
+	 * @param mixed $data
21
+	 * @param array $options
22
+	 * @return string
23
+	 */
24
+	public static function serialize($data, array $options = []): string;
25 25
 
26
-    /**
27
-     * @param string $data
28
-     * @param array $options
29
-     * @return mixed
30
-     */
31
-    public static function unserialize(string $data, array $options = []);
26
+	/**
27
+	 * @param string $data
28
+	 * @param array $options
29
+	 * @return mixed
30
+	 */
31
+	public static function unserialize(string $data, array $options = []);
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@
 block discarded – undo
14 14
 
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
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/CsvSerializer.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,39 +24,39 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@
 block discarded – undo
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
      * 
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/Utility.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,32 +23,32 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@
 block discarded – undo
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
      * 
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Serializer/NDJsonSerializer.php 3 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -25,51 +25,51 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Async/OnSuccessInterface.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Transport/Async/OnSuccessDefault.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.