Completed
Push — master ( 8e973a...811a95 )
by
unknown
03:40 queued 01:04
created
lib/Vendor/Psr/EventDispatcher/ListenerProviderInterface.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,12 +8,12 @@
 block discarded – undo
8 8
  */
9 9
 interface ListenerProviderInterface
10 10
 {
11
-    /**
12
-     * @param object $event
13
-     *   An event for which to return the relevant listeners.
14
-     * @return iterable[callable]
15
-     *   An iterable (array, iterator, or generator) of callables.  Each
16
-     *   callable MUST be type-compatible with $event.
17
-     */
18
-    public function getListenersForEvent(object $event) : iterable;
11
+	/**
12
+	 * @param object $event
13
+	 *   An event for which to return the relevant listeners.
14
+	 * @return iterable[callable]
15
+	 *   An iterable (array, iterator, or generator) of callables.  Each
16
+	 *   callable MUST be type-compatible with $event.
17
+	 */
18
+	public function getListenersForEvent(object $event) : iterable;
19 19
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Psr\EventDispatcher;
5 5
 
6 6
 /**
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,7 @@
 block discarded – undo
6 6
 /**
7 7
  * Mapper from an event to the listeners that are applicable to that event.
8 8
  */
9
-interface ListenerProviderInterface
10
-{
9
+interface ListenerProviderInterface {
11 10
     /**
12 11
      * @param object $event
13 12
      *   An event for which to return the relevant listeners.
Please login to merge, or discard this patch.
lib/Vendor/Psr/EventDispatcher/EventDispatcherInterface.php 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@
 block discarded – undo
8 8
  */
9 9
 interface EventDispatcherInterface
10 10
 {
11
-    /**
12
-     * Provide all relevant listeners with an event to process.
13
-     *
14
-     * @param object $event
15
-     *   The object to process.
16
-     *
17
-     * @return object
18
-     *   The Event that was passed, now modified by listeners.
19
-     */
20
-    public function dispatch(object $event);
11
+	/**
12
+	 * Provide all relevant listeners with an event to process.
13
+	 *
14
+	 * @param object $event
15
+	 *   The object to process.
16
+	 *
17
+	 * @return object
18
+	 *   The Event that was passed, now modified by listeners.
19
+	 */
20
+	public function dispatch(object $event);
21 21
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,7 @@
 block discarded – undo
6 6
 /**
7 7
  * Defines a dispatcher for events.
8 8
  */
9
-interface EventDispatcherInterface
10
-{
9
+interface EventDispatcherInterface {
11 10
     /**
12 11
      * Provide all relevant listeners with an event to process.
13 12
      *
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Psr\EventDispatcher;
5 5
 
6 6
 /**
Please login to merge, or discard this patch.
lib/Vendor/Psr/EventDispatcher/StoppableEventInterface.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,15 +12,15 @@
 block discarded – undo
12 12
  */
13 13
 interface StoppableEventInterface
14 14
 {
15
-    /**
16
-     * Is propagation stopped?
17
-     *
18
-     * This will typically only be used by the Dispatcher to determine if the
19
-     * previous listener halted propagation.
20
-     *
21
-     * @return bool
22
-     *   True if the Event is complete and no further listeners should be called.
23
-     *   False to continue calling listeners.
24
-     */
25
-    public function isPropagationStopped() : bool;
15
+	/**
16
+	 * Is propagation stopped?
17
+	 *
18
+	 * This will typically only be used by the Dispatcher to determine if the
19
+	 * previous listener halted propagation.
20
+	 *
21
+	 * @return bool
22
+	 *   True if the Event is complete and no further listeners should be called.
23
+	 *   False to continue calling listeners.
24
+	 */
25
+	public function isPropagationStopped() : bool;
26 26
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,7 @@
 block discarded – undo
10 10
  * is marked as stopped after each listener is called.  If it is then it should
11 11
  * return immediately without calling any further Listeners.
12 12
  */
13
-interface StoppableEventInterface
14
-{
13
+interface StoppableEventInterface {
15 14
     /**
16 15
      * Is propagation stopped?
17 16
      *
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Psr\EventDispatcher;
5 5
 
6 6
 /**
Please login to merge, or discard this patch.
lib/Vendor/Psr/Container/ContainerExceptionInterface.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,6 +6,5 @@
 block discarded – undo
6 6
 /**
7 7
  * Base interface representing a generic exception in a container.
8 8
  */
9
-interface ContainerExceptionInterface extends Throwable
10
-{
9
+interface ContainerExceptionInterface extends Throwable {
11 10
 }
Please login to merge, or discard this patch.
lib/Vendor/Psr/Container/ContainerInterface.php 3 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -8,27 +8,27 @@
 block discarded – undo
8 8
  */
9 9
 interface ContainerInterface
10 10
 {
11
-    /**
12
-     * Finds an entry of the container by its identifier and returns it.
13
-     *
14
-     * @param string $id Identifier of the entry to look for.
15
-     *
16
-     * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
17
-     * @throws ContainerExceptionInterface Error while retrieving the entry.
18
-     *
19
-     * @return mixed Entry.
20
-     */
21
-    public function get(string $id);
22
-    /**
23
-     * Returns true if the container can return an entry for the given identifier.
24
-     * Returns false otherwise.
25
-     *
26
-     * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
27
-     * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
28
-     *
29
-     * @param string $id Identifier of the entry to look for.
30
-     *
31
-     * @return bool
32
-     */
33
-    public function has(string $id) : bool;
11
+	/**
12
+	 * Finds an entry of the container by its identifier and returns it.
13
+	 *
14
+	 * @param string $id Identifier of the entry to look for.
15
+	 *
16
+	 * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
17
+	 * @throws ContainerExceptionInterface Error while retrieving the entry.
18
+	 *
19
+	 * @return mixed Entry.
20
+	 */
21
+	public function get(string $id);
22
+	/**
23
+	 * Returns true if the container can return an entry for the given identifier.
24
+	 * Returns false otherwise.
25
+	 *
26
+	 * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
27
+	 * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
28
+	 *
29
+	 * @param string $id Identifier of the entry to look for.
30
+	 *
31
+	 * @return bool
32
+	 */
33
+	public function has(string $id) : bool;
34 34
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare (strict_types=1);
3
+declare(strict_types=1);
4 4
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Container;
5 5
 
6 6
 /**
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,7 @@
 block discarded – undo
6 6
 /**
7 7
  * Describes the interface of a container that exposes methods to read its entries.
8 8
  */
9
-interface ContainerInterface
10
-{
9
+interface ContainerInterface {
11 10
     /**
12 11
      * Finds an entry of the container by its identifier and returns it.
13 12
      *
Please login to merge, or discard this patch.
lib/Vendor/Psr/Container/NotFoundExceptionInterface.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,6 +5,5 @@
 block discarded – undo
5 5
 /**
6 6
  * No entry was found in the container.
7 7
  */
8
-interface NotFoundExceptionInterface extends ContainerExceptionInterface
9
-{
8
+interface NotFoundExceptionInterface extends ContainerExceptionInterface {
10 9
 }
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Client.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
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\Elasticsearch;
16 16
 
17 17
 use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Response\Elasticsearch;
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -26,123 +26,123 @@
 block discarded – undo
26 26
 use Psr\Log\LoggerInterface;
27 27
 final class Client implements ClientInterface
28 28
 {
29
-    const CLIENT_NAME = 'es';
30
-    const VERSION = '8.13.0';
31
-    const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
32
-    use ClientEndpointsTrait;
33
-    use EndpointTrait;
34
-    use NamespaceTrait;
35
-    protected Transport $transport;
36
-    protected LoggerInterface $logger;
37
-    /**
38
-     * Specify is the request is asyncronous
39
-     */
40
-    protected bool $async = \false;
41
-    /**
42
-     * Enable or disable the x-elastic-meta-header
43
-     */
44
-    protected bool $elasticMetaHeader = \true;
45
-    /**
46
-     * Enable or disable the response Exception
47
-     */
48
-    protected bool $responseException = \true;
49
-    /**
50
-     * The endpoint namespace storage 
51
-     */
52
-    protected array $namespace;
53
-    public function __construct(Transport $transport, LoggerInterface $logger)
54
-    {
55
-        $this->transport = $transport;
56
-        $this->logger = $logger;
57
-        $this->defaultTransportSettings($this->transport);
58
-    }
59
-    /**
60
-     * @inheritdoc
61
-     */
62
-    public function getTransport() : Transport
63
-    {
64
-        return $this->transport;
65
-    }
66
-    /**
67
-     * @inheritdoc
68
-     */
69
-    public function getLogger() : LoggerInterface
70
-    {
71
-        return $this->logger;
72
-    }
73
-    /**
74
-     * Set the default settings for Elasticsearch
75
-     */
76
-    protected function defaultTransportSettings(Transport $transport) : void
77
-    {
78
-        $transport->setUserAgent('elasticsearch-php', self::VERSION);
79
-    }
80
-    /**
81
-     * @inheritdoc
82
-     */
83
-    public function setAsync(bool $async) : self
84
-    {
85
-        $this->async = $async;
86
-        return $this;
87
-    }
88
-    /**
89
-     * @inheritdoc
90
-     */
91
-    public function getAsync() : bool
92
-    {
93
-        return $this->async;
94
-    }
95
-    /**
96
-     * @inheritdoc
97
-     */
98
-    public function setElasticMetaHeader(bool $active) : self
99
-    {
100
-        $this->elasticMetaHeader = $active;
101
-        return $this;
102
-    }
103
-    /**
104
-     * @inheritdoc
105
-     */
106
-    public function getElasticMetaHeader() : bool
107
-    {
108
-        return $this->elasticMetaHeader;
109
-    }
110
-    /**
111
-     * @inheritdoc
112
-     */
113
-    public function setResponseException(bool $active) : self
114
-    {
115
-        $this->responseException = $active;
116
-        return $this;
117
-    }
118
-    /**
119
-     * @inheritdoc
120
-     */
121
-    public function getResponseException() : bool
122
-    {
123
-        return $this->responseException;
124
-    }
125
-    /**
126
-     * @inheritdoc
127
-     */
128
-    public function sendRequest(RequestInterface $request)
129
-    {
130
-        // If async returns a Promise
131
-        if ($this->getAsync()) {
132
-            if ($this->getElasticMetaHeader()) {
133
-                $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, \true);
134
-            }
135
-            $this->transport->setAsyncOnSuccess($request->getMethod() === 'HEAD' ? new AsyncOnSuccessNoException() : ($this->getResponseException() ? new AsyncOnSuccess() : new AsyncOnSuccessNoException()));
136
-            return $this->transport->sendAsyncRequest($request);
137
-        }
138
-        if ($this->getElasticMetaHeader()) {
139
-            $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, \false);
140
-        }
141
-        $start = \microtime(\true);
142
-        $response = $this->transport->sendRequest($request);
143
-        $this->logger->info(\sprintf("Response time in %.3f sec", \microtime(\true) - $start));
144
-        $result = new Elasticsearch();
145
-        $result->setResponse($response, $request->getMethod() === 'HEAD' ? \false : $this->getResponseException());
146
-        return $result;
147
-    }
29
+	const CLIENT_NAME = 'es';
30
+	const VERSION = '8.13.0';
31
+	const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
32
+	use ClientEndpointsTrait;
33
+	use EndpointTrait;
34
+	use NamespaceTrait;
35
+	protected Transport $transport;
36
+	protected LoggerInterface $logger;
37
+	/**
38
+	 * Specify is the request is asyncronous
39
+	 */
40
+	protected bool $async = \false;
41
+	/**
42
+	 * Enable or disable the x-elastic-meta-header
43
+	 */
44
+	protected bool $elasticMetaHeader = \true;
45
+	/**
46
+	 * Enable or disable the response Exception
47
+	 */
48
+	protected bool $responseException = \true;
49
+	/**
50
+	 * The endpoint namespace storage 
51
+	 */
52
+	protected array $namespace;
53
+	public function __construct(Transport $transport, LoggerInterface $logger)
54
+	{
55
+		$this->transport = $transport;
56
+		$this->logger = $logger;
57
+		$this->defaultTransportSettings($this->transport);
58
+	}
59
+	/**
60
+	 * @inheritdoc
61
+	 */
62
+	public function getTransport() : Transport
63
+	{
64
+		return $this->transport;
65
+	}
66
+	/**
67
+	 * @inheritdoc
68
+	 */
69
+	public function getLogger() : LoggerInterface
70
+	{
71
+		return $this->logger;
72
+	}
73
+	/**
74
+	 * Set the default settings for Elasticsearch
75
+	 */
76
+	protected function defaultTransportSettings(Transport $transport) : void
77
+	{
78
+		$transport->setUserAgent('elasticsearch-php', self::VERSION);
79
+	}
80
+	/**
81
+	 * @inheritdoc
82
+	 */
83
+	public function setAsync(bool $async) : self
84
+	{
85
+		$this->async = $async;
86
+		return $this;
87
+	}
88
+	/**
89
+	 * @inheritdoc
90
+	 */
91
+	public function getAsync() : bool
92
+	{
93
+		return $this->async;
94
+	}
95
+	/**
96
+	 * @inheritdoc
97
+	 */
98
+	public function setElasticMetaHeader(bool $active) : self
99
+	{
100
+		$this->elasticMetaHeader = $active;
101
+		return $this;
102
+	}
103
+	/**
104
+	 * @inheritdoc
105
+	 */
106
+	public function getElasticMetaHeader() : bool
107
+	{
108
+		return $this->elasticMetaHeader;
109
+	}
110
+	/**
111
+	 * @inheritdoc
112
+	 */
113
+	public function setResponseException(bool $active) : self
114
+	{
115
+		$this->responseException = $active;
116
+		return $this;
117
+	}
118
+	/**
119
+	 * @inheritdoc
120
+	 */
121
+	public function getResponseException() : bool
122
+	{
123
+		return $this->responseException;
124
+	}
125
+	/**
126
+	 * @inheritdoc
127
+	 */
128
+	public function sendRequest(RequestInterface $request)
129
+	{
130
+		// If async returns a Promise
131
+		if ($this->getAsync()) {
132
+			if ($this->getElasticMetaHeader()) {
133
+				$this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, \true);
134
+			}
135
+			$this->transport->setAsyncOnSuccess($request->getMethod() === 'HEAD' ? new AsyncOnSuccessNoException() : ($this->getResponseException() ? new AsyncOnSuccess() : new AsyncOnSuccessNoException()));
136
+			return $this->transport->sendAsyncRequest($request);
137
+		}
138
+		if ($this->getElasticMetaHeader()) {
139
+			$this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, \false);
140
+		}
141
+		$start = \microtime(\true);
142
+		$response = $this->transport->sendRequest($request);
143
+		$this->logger->info(\sprintf("Response time in %.3f sec", \microtime(\true) - $start));
144
+		$result = new Elasticsearch();
145
+		$result->setResponse($response, $request->getMethod() === 'HEAD' ? \false : $this->getResponseException());
146
+		return $result;
147
+	}
148 148
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@
 block discarded – undo
24 24
 use OCA\FullTextSearch_Elasticsearch\Vendor\Http\Promise\Promise;
25 25
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestInterface;
26 26
 use Psr\Log\LoggerInterface;
27
-final class Client implements ClientInterface
28
-{
27
+final class Client implements ClientInterface {
29 28
     const CLIENT_NAME = 'es';
30 29
     const VERSION = '8.13.0';
31 30
     const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Response/ElasticsearchInterface.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@
 block discarded – undo
17 17
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\ResponseInterface;
18 18
 interface ElasticsearchInterface
19 19
 {
20
-    /**
21
-     * Set the HTTP PSR-7 response 
22
-     */
23
-    public function setResponse(ResponseInterface $response, bool $throwException = \true) : void;
20
+	/**
21
+	 * Set the HTTP PSR-7 response 
22
+	 */
23
+	public function setResponse(ResponseInterface $response, bool $throwException = \true) : void;
24 24
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
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\Elasticsearch\Response;
16 16
 
17 17
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\ResponseInterface;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@
 block discarded – undo
15 15
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Response;
16 16
 
17 17
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\ResponseInterface;
18
-interface ElasticsearchInterface
19
-{
18
+interface ElasticsearchInterface {
20 19
     /**
21 20
      * Set the HTTP PSR-7 response 
22 21
      */
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Response/Elasticsearch.php 2 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -34,220 +34,220 @@
 block discarded – undo
34 34
  */
35 35
 class Elasticsearch implements ElasticsearchInterface, ResponseInterface, ArrayAccess
36 36
 {
37
-    const HEADER_CHECK = 'X-Elastic-Product';
38
-    const PRODUCT_NAME = 'Elasticsearch';
39
-    use ProductCheckTrait;
40
-    use MessageResponseTrait;
41
-    protected array $asArray;
42
-    protected object $asObject;
43
-    protected string $asString;
44
-    /**
45
-     * The PSR-7 response
46
-     */
47
-    protected ResponseInterface $response;
48
-    /**
49
-     * Enable or disable the response Exception
50
-     */
51
-    protected bool $responseException;
52
-    /**
53
-     * @throws ClientResponseException if status code 4xx
54
-     * @throws ServerResponseException if status code 5xx
55
-     */
56
-    public function setResponse(ResponseInterface $response, bool $throwException = \true) : void
57
-    {
58
-        $this->productCheck($response);
59
-        $this->response = $response;
60
-        $status = $response->getStatusCode();
61
-        if ($throwException && $status > 399 && $status < 500) {
62
-            $error = new ClientResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
63
-            throw $error->setResponse($response);
64
-        } elseif ($throwException && $status > 499 && $status < 600) {
65
-            $error = new ServerResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
66
-            throw $error->setResponse($response);
67
-        }
68
-    }
69
-    /**
70
-     * Return true if status code is 2xx
71
-     */
72
-    public function asBool() : bool
73
-    {
74
-        return $this->response->getStatusCode() >= 200 && $this->response->getStatusCode() < 300;
75
-    }
76
-    /**
77
-     * Converts the body content to array, if possible.
78
-     * Otherwise, it throws an UnknownContentTypeException
79
-     * if Content-Type is not specified or unknown.
80
-     * 
81
-     * @throws UnknownContentTypeException
82
-     */
83
-    public function asArray() : array
84
-    {
85
-        if (isset($this->asArray)) {
86
-            return $this->asArray;
87
-        }
88
-        if (!$this->response->hasHeader('Content-Type')) {
89
-            throw new UnknownContentTypeException('No Content-Type specified in the response');
90
-        }
91
-        $contentType = $this->response->getHeaderLine('Content-Type');
92
-        if (\strpos($contentType, 'application/json') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) {
93
-            $this->asArray = JsonSerializer::unserialize($this->asString());
94
-            return $this->asArray;
95
-        }
96
-        if (\strpos($contentType, 'application/x-ndjson') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) {
97
-            $this->asArray = NDJsonSerializer::unserialize($this->asString());
98
-            return $this->asArray;
99
-        }
100
-        if (\strpos($contentType, 'text/csv') !== \false) {
101
-            $this->asArray = CsvSerializer::unserialize($this->asString());
102
-            return $this->asArray;
103
-        }
104
-        throw new UnknownContentTypeException(\sprintf("Cannot deserialize the reponse as array with Content-Type: %s", $contentType));
105
-    }
106
-    /**
107
-     * Converts the body content to object, if possible.
108
-     * Otherwise, it throws an UnknownContentTypeException
109
-     * if Content-Type is not specified or unknown.
110
-     * 
111
-     * @throws UnknownContentTypeException
112
-     */
113
-    public function asObject() : object
114
-    {
115
-        if (isset($this->asObject)) {
116
-            return $this->asObject;
117
-        }
118
-        $contentType = $this->response->getHeaderLine('Content-Type');
119
-        if (\strpos($contentType, 'application/json') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) {
120
-            $this->asObject = JsonSerializer::unserialize($this->asString(), ['type' => 'object']);
121
-            return $this->asObject;
122
-        }
123
-        if (\strpos($contentType, 'application/x-ndjson') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) {
124
-            $this->asObject = NDJsonSerializer::unserialize($this->asString(), ['type' => 'object']);
125
-            return $this->asObject;
126
-        }
127
-        if (\strpos($contentType, 'text/xml') !== \false || \strpos($contentType, 'application/xml') !== \false) {
128
-            $this->asObject = XmlSerializer::unserialize($this->asString());
129
-            return $this->asObject;
130
-        }
131
-        throw new UnknownContentTypeException(\sprintf("Cannot deserialize the reponse as object with Content-Type: %s", $contentType));
132
-    }
133
-    /**
134
-     * Converts the body content to string
135
-     */
136
-    public function asString() : string
137
-    {
138
-        if (empty($this->asString)) {
139
-            $this->asString = (string) $this->response->getBody();
140
-        }
141
-        return $this->asString;
142
-    }
143
-    /**
144
-     * Converts the body content to string
145
-     */
146
-    public function __toString() : string
147
-    {
148
-        return $this->asString();
149
-    }
150
-    /**
151
-     * Access the body content as object properties
152
-     * 
153
-     * @see https://www.php.net/manual/en/language.oop5.overloading.php#object.get
154
-     */
155
-    public function __get($name)
156
-    {
157
-        return $this->asObject()->{$name} ?? null;
158
-    }
159
-    /**
160
-     * ArrayAccess interface
161
-     * 
162
-     * @see https://www.php.net/manual/en/class.arrayaccess.php
163
-     */
164
-    public function offsetExists($offset) : bool
165
-    {
166
-        return isset($this->asArray()[$offset]);
167
-    }
168
-    /**
169
-     * ArrayAccess interface
170
-     * 
171
-     * @see https://www.php.net/manual/en/class.arrayaccess.php
172
-     *
173
-     * @return mixed
174
-     */
175
-    #[\ReturnTypeWillChange]
176
-    public function offsetGet($offset)
177
-    {
178
-        return $this->asArray()[$offset];
179
-    }
180
-    /**
181
-     * ArrayAccess interface
182
-     * 
183
-     * @see https://www.php.net/manual/en/class.arrayaccess.php
184
-     */
185
-    public function offsetSet($offset, $value) : void
186
-    {
187
-        throw new ArrayAccessException('The array is reading only');
188
-    }
189
-    /**
190
-     * ArrayAccess interface
191
-     * 
192
-     * @see https://www.php.net/manual/en/class.arrayaccess.php
193
-     */
194
-    public function offsetUnset($offset) : void
195
-    {
196
-        throw new ArrayAccessException('The array is reading only');
197
-    }
198
-    /**
199
-     * Map the response body to an object of a specific class
200
-     * by default the class is the PHP standard one (stdClass)
201
-     * 
202
-     * This mapping works only for ES|QL results (with columns and values)
203
-     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/esql.html
204
-     * 
205
-     * @return object[] 
206
-     */
207
-    public function mapTo(string $class = stdClass::class) : array
208
-    {
209
-        $response = $this->asArray();
210
-        if (!isset($response['columns']) || !isset($response['values'])) {
211
-            throw new UnknownContentTypeException(\sprintf("The response is not a valid ES|QL result. I cannot mapTo(\"%s\")", $class));
212
-        }
213
-        $iterator = [];
214
-        $ncol = \count($response['columns']);
215
-        foreach ($response['values'] as $value) {
216
-            $obj = new $class();
217
-            for ($i = 0; $i < $ncol; $i++) {
218
-                $field = Utility::formatVariableName($response['columns'][$i]['name']);
219
-                if ($class !== stdClass::class && !\property_exists($obj, $field)) {
220
-                    continue;
221
-                }
222
-                switch ($response['columns'][$i]['type']) {
223
-                    case 'boolean':
224
-                        $obj->{$field} = (bool) $value[$i];
225
-                        break;
226
-                    case 'date':
227
-                        $obj->{$field} = new DateTime($value[$i]);
228
-                        break;
229
-                    case 'alias':
230
-                    case 'text':
231
-                    case 'keyword':
232
-                    case 'ip':
233
-                        $obj->{$field} = (string) $value[$i];
234
-                        break;
235
-                    case 'integer':
236
-                        $obj->{$field} = (int) $value[$i];
237
-                        break;
238
-                    case 'long':
239
-                    case 'double':
240
-                        $obj->{$field} = (float) $value[$i];
241
-                        break;
242
-                    case 'null':
243
-                        $obj->{$field} = null;
244
-                        break;
245
-                    default:
246
-                        $obj->{$field} = $value[$i];
247
-                }
248
-            }
249
-            $iterator[] = $obj;
250
-        }
251
-        return $iterator;
252
-    }
37
+	const HEADER_CHECK = 'X-Elastic-Product';
38
+	const PRODUCT_NAME = 'Elasticsearch';
39
+	use ProductCheckTrait;
40
+	use MessageResponseTrait;
41
+	protected array $asArray;
42
+	protected object $asObject;
43
+	protected string $asString;
44
+	/**
45
+	 * The PSR-7 response
46
+	 */
47
+	protected ResponseInterface $response;
48
+	/**
49
+	 * Enable or disable the response Exception
50
+	 */
51
+	protected bool $responseException;
52
+	/**
53
+	 * @throws ClientResponseException if status code 4xx
54
+	 * @throws ServerResponseException if status code 5xx
55
+	 */
56
+	public function setResponse(ResponseInterface $response, bool $throwException = \true) : void
57
+	{
58
+		$this->productCheck($response);
59
+		$this->response = $response;
60
+		$status = $response->getStatusCode();
61
+		if ($throwException && $status > 399 && $status < 500) {
62
+			$error = new ClientResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
63
+			throw $error->setResponse($response);
64
+		} elseif ($throwException && $status > 499 && $status < 600) {
65
+			$error = new ServerResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
66
+			throw $error->setResponse($response);
67
+		}
68
+	}
69
+	/**
70
+	 * Return true if status code is 2xx
71
+	 */
72
+	public function asBool() : bool
73
+	{
74
+		return $this->response->getStatusCode() >= 200 && $this->response->getStatusCode() < 300;
75
+	}
76
+	/**
77
+	 * Converts the body content to array, if possible.
78
+	 * Otherwise, it throws an UnknownContentTypeException
79
+	 * if Content-Type is not specified or unknown.
80
+	 * 
81
+	 * @throws UnknownContentTypeException
82
+	 */
83
+	public function asArray() : array
84
+	{
85
+		if (isset($this->asArray)) {
86
+			return $this->asArray;
87
+		}
88
+		if (!$this->response->hasHeader('Content-Type')) {
89
+			throw new UnknownContentTypeException('No Content-Type specified in the response');
90
+		}
91
+		$contentType = $this->response->getHeaderLine('Content-Type');
92
+		if (\strpos($contentType, 'application/json') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) {
93
+			$this->asArray = JsonSerializer::unserialize($this->asString());
94
+			return $this->asArray;
95
+		}
96
+		if (\strpos($contentType, 'application/x-ndjson') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) {
97
+			$this->asArray = NDJsonSerializer::unserialize($this->asString());
98
+			return $this->asArray;
99
+		}
100
+		if (\strpos($contentType, 'text/csv') !== \false) {
101
+			$this->asArray = CsvSerializer::unserialize($this->asString());
102
+			return $this->asArray;
103
+		}
104
+		throw new UnknownContentTypeException(\sprintf("Cannot deserialize the reponse as array with Content-Type: %s", $contentType));
105
+	}
106
+	/**
107
+	 * Converts the body content to object, if possible.
108
+	 * Otherwise, it throws an UnknownContentTypeException
109
+	 * if Content-Type is not specified or unknown.
110
+	 * 
111
+	 * @throws UnknownContentTypeException
112
+	 */
113
+	public function asObject() : object
114
+	{
115
+		if (isset($this->asObject)) {
116
+			return $this->asObject;
117
+		}
118
+		$contentType = $this->response->getHeaderLine('Content-Type');
119
+		if (\strpos($contentType, 'application/json') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) {
120
+			$this->asObject = JsonSerializer::unserialize($this->asString(), ['type' => 'object']);
121
+			return $this->asObject;
122
+		}
123
+		if (\strpos($contentType, 'application/x-ndjson') !== \false || \strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) {
124
+			$this->asObject = NDJsonSerializer::unserialize($this->asString(), ['type' => 'object']);
125
+			return $this->asObject;
126
+		}
127
+		if (\strpos($contentType, 'text/xml') !== \false || \strpos($contentType, 'application/xml') !== \false) {
128
+			$this->asObject = XmlSerializer::unserialize($this->asString());
129
+			return $this->asObject;
130
+		}
131
+		throw new UnknownContentTypeException(\sprintf("Cannot deserialize the reponse as object with Content-Type: %s", $contentType));
132
+	}
133
+	/**
134
+	 * Converts the body content to string
135
+	 */
136
+	public function asString() : string
137
+	{
138
+		if (empty($this->asString)) {
139
+			$this->asString = (string) $this->response->getBody();
140
+		}
141
+		return $this->asString;
142
+	}
143
+	/**
144
+	 * Converts the body content to string
145
+	 */
146
+	public function __toString() : string
147
+	{
148
+		return $this->asString();
149
+	}
150
+	/**
151
+	 * Access the body content as object properties
152
+	 * 
153
+	 * @see https://www.php.net/manual/en/language.oop5.overloading.php#object.get
154
+	 */
155
+	public function __get($name)
156
+	{
157
+		return $this->asObject()->{$name} ?? null;
158
+	}
159
+	/**
160
+	 * ArrayAccess interface
161
+	 * 
162
+	 * @see https://www.php.net/manual/en/class.arrayaccess.php
163
+	 */
164
+	public function offsetExists($offset) : bool
165
+	{
166
+		return isset($this->asArray()[$offset]);
167
+	}
168
+	/**
169
+	 * ArrayAccess interface
170
+	 * 
171
+	 * @see https://www.php.net/manual/en/class.arrayaccess.php
172
+	 *
173
+	 * @return mixed
174
+	 */
175
+	#[\ReturnTypeWillChange]
176
+	public function offsetGet($offset)
177
+	{
178
+		return $this->asArray()[$offset];
179
+	}
180
+	/**
181
+	 * ArrayAccess interface
182
+	 * 
183
+	 * @see https://www.php.net/manual/en/class.arrayaccess.php
184
+	 */
185
+	public function offsetSet($offset, $value) : void
186
+	{
187
+		throw new ArrayAccessException('The array is reading only');
188
+	}
189
+	/**
190
+	 * ArrayAccess interface
191
+	 * 
192
+	 * @see https://www.php.net/manual/en/class.arrayaccess.php
193
+	 */
194
+	public function offsetUnset($offset) : void
195
+	{
196
+		throw new ArrayAccessException('The array is reading only');
197
+	}
198
+	/**
199
+	 * Map the response body to an object of a specific class
200
+	 * by default the class is the PHP standard one (stdClass)
201
+	 * 
202
+	 * This mapping works only for ES|QL results (with columns and values)
203
+	 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/esql.html
204
+	 * 
205
+	 * @return object[] 
206
+	 */
207
+	public function mapTo(string $class = stdClass::class) : array
208
+	{
209
+		$response = $this->asArray();
210
+		if (!isset($response['columns']) || !isset($response['values'])) {
211
+			throw new UnknownContentTypeException(\sprintf("The response is not a valid ES|QL result. I cannot mapTo(\"%s\")", $class));
212
+		}
213
+		$iterator = [];
214
+		$ncol = \count($response['columns']);
215
+		foreach ($response['values'] as $value) {
216
+			$obj = new $class();
217
+			for ($i = 0; $i < $ncol; $i++) {
218
+				$field = Utility::formatVariableName($response['columns'][$i]['name']);
219
+				if ($class !== stdClass::class && !\property_exists($obj, $field)) {
220
+					continue;
221
+				}
222
+				switch ($response['columns'][$i]['type']) {
223
+					case 'boolean':
224
+						$obj->{$field} = (bool) $value[$i];
225
+						break;
226
+					case 'date':
227
+						$obj->{$field} = new DateTime($value[$i]);
228
+						break;
229
+					case 'alias':
230
+					case 'text':
231
+					case 'keyword':
232
+					case 'ip':
233
+						$obj->{$field} = (string) $value[$i];
234
+						break;
235
+					case 'integer':
236
+						$obj->{$field} = (int) $value[$i];
237
+						break;
238
+					case 'long':
239
+					case 'double':
240
+						$obj->{$field} = (float) $value[$i];
241
+						break;
242
+					case 'null':
243
+						$obj->{$field} = null;
244
+						break;
245
+					default:
246
+						$obj->{$field} = $value[$i];
247
+				}
248
+			}
249
+			$iterator[] = $obj;
250
+		}
251
+		return $iterator;
252
+	}
253 253
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
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\Elasticsearch\Response;
16 16
 
17 17
 use ArrayAccess;
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
         $this->response = $response;
60 60
         $status = $response->getStatusCode();
61 61
         if ($throwException && $status > 399 && $status < 500) {
62
-            $error = new ClientResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
62
+            $error = new ClientResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string)$response->getBody()), $status);
63 63
             throw $error->setResponse($response);
64 64
         } elseif ($throwException && $status > 499 && $status < 600) {
65
-            $error = new ServerResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), $status);
65
+            $error = new ServerResponseException(\sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string)$response->getBody()), $status);
66 66
             throw $error->setResponse($response);
67 67
         }
68 68
     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     public function asString() : string
137 137
     {
138 138
         if (empty($this->asString)) {
139
-            $this->asString = (string) $this->response->getBody();
139
+            $this->asString = (string)$this->response->getBody();
140 140
         }
141 141
         return $this->asString;
142 142
     }
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
                 }
222 222
                 switch ($response['columns'][$i]['type']) {
223 223
                     case 'boolean':
224
-                        $obj->{$field} = (bool) $value[$i];
224
+                        $obj->{$field} = (bool)$value[$i];
225 225
                         break;
226 226
                     case 'date':
227 227
                         $obj->{$field} = new DateTime($value[$i]);
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
                     case 'text':
231 231
                     case 'keyword':
232 232
                     case 'ip':
233
-                        $obj->{$field} = (string) $value[$i];
233
+                        $obj->{$field} = (string)$value[$i];
234 234
                         break;
235 235
                     case 'integer':
236
-                        $obj->{$field} = (int) $value[$i];
236
+                        $obj->{$field} = (int)$value[$i];
237 237
                         break;
238 238
                     case 'long':
239 239
                     case 'double':
240
-                        $obj->{$field} = (float) $value[$i];
240
+                        $obj->{$field} = (float)$value[$i];
241 241
                         break;
242 242
                     case 'null':
243 243
                         $obj->{$field} = null;
Please login to merge, or discard this patch.