Completed
Pull Request — master (#359)
by Maxence
41s
created
lib/Vendor/Elastic/Elasticsearch/Exception/ProductCheckException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use RuntimeException;
18 18
 
19
-class ProductCheckException extends RuntimeException implements ElasticsearchException
20
-{
19
+class ProductCheckException extends RuntimeException implements ElasticsearchException {
21 20
     
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Exception/AuthenticationException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use Exception;
18 18
 
19
-class AuthenticationException extends Exception implements ElasticsearchException
20
-{
19
+class AuthenticationException extends Exception implements ElasticsearchException {
21 20
 
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Exception/ContentTypeException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use Exception;
18 18
 
19
-class ContentTypeException extends Exception implements ElasticsearchException
20
-{
19
+class ContentTypeException extends Exception implements ElasticsearchException {
21 20
 
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Exception/ArrayAccessException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use Exception;
18 18
 
19
-class ArrayAccessException extends Exception implements ElasticsearchException
20
-{
19
+class ArrayAccessException extends Exception implements ElasticsearchException {
21 20
 
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Exception/ConfigException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use Exception;
18 18
 
19
-class ConfigException extends Exception implements ElasticsearchException
20
-{
19
+class ConfigException extends Exception implements ElasticsearchException {
21 20
 
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Exception/InvalidArgumentException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 
17 17
 use InvalidArgumentException as InvalidArgument;
18 18
 
19
-class InvalidArgumentException extends InvalidArgument implements ElasticsearchException
20
-{
19
+class InvalidArgumentException extends InvalidArgument implements ElasticsearchException {
21 20
 
22 21
 }
23 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Client.php 3 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -27,149 +27,149 @@
 block discarded – undo
27 27
 
28 28
 final class Client implements ClientInterface
29 29
 {
30
-    const CLIENT_NAME = 'es';
31
-    const VERSION = '8.13.0';
32
-    const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
30
+	const CLIENT_NAME = 'es';
31
+	const VERSION = '8.13.0';
32
+	const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
33 33
     
34
-    use ClientEndpointsTrait;
35
-    use EndpointTrait;
36
-    use NamespaceTrait;
34
+	use ClientEndpointsTrait;
35
+	use EndpointTrait;
36
+	use NamespaceTrait;
37 37
     
38
-    protected Transport $transport;
39
-    protected LoggerInterface $logger;
38
+	protected Transport $transport;
39
+	protected LoggerInterface $logger;
40 40
 
41
-    /**
42
-     * Specify is the request is asyncronous
43
-     */
44
-    protected bool $async = false;
41
+	/**
42
+	 * Specify is the request is asyncronous
43
+	 */
44
+	protected bool $async = false;
45 45
     
46
-    /**
47
-     * Enable or disable the x-elastic-meta-header
48
-     */
49
-    protected bool $elasticMetaHeader = true;
50
-
51
-    /**
52
-     * Enable or disable the response Exception
53
-     */
54
-    protected bool $responseException = true;
55
-
56
-    /**
57
-     * The endpoint namespace storage 
58
-     */
59
-    protected array $namespace;
60
-
61
-    public function __construct(
62
-        Transport $transport, 
63
-        LoggerInterface $logger
64
-    ) {
65
-        $this->transport = $transport;
66
-        $this->logger = $logger;       
46
+	/**
47
+	 * Enable or disable the x-elastic-meta-header
48
+	 */
49
+	protected bool $elasticMetaHeader = true;
50
+
51
+	/**
52
+	 * Enable or disable the response Exception
53
+	 */
54
+	protected bool $responseException = true;
55
+
56
+	/**
57
+	 * The endpoint namespace storage 
58
+	 */
59
+	protected array $namespace;
60
+
61
+	public function __construct(
62
+		Transport $transport, 
63
+		LoggerInterface $logger
64
+	) {
65
+		$this->transport = $transport;
66
+		$this->logger = $logger;       
67 67
         
68
-        $this->defaultTransportSettings($this->transport);
69
-    }
70
-
71
-    /**
72
-     * @inheritdoc
73
-     */
74
-    public function getTransport(): Transport
75
-    {
76
-        return $this->transport;
77
-    }
78
-
79
-    /**
80
-     * @inheritdoc
81
-     */
82
-    public function getLogger(): LoggerInterface
83
-    {
84
-        return $this->logger;
85
-    }
86
-
87
-    /**
88
-     * Set the default settings for Elasticsearch
89
-     */
90
-    protected function defaultTransportSettings(Transport $transport): void
91
-    {
92
-        $transport->setUserAgent('elasticsearch-php', self::VERSION);
93
-    }
94
-
95
-    /**
96
-     * @inheritdoc
97
-     */
98
-    public function setAsync(bool $async): self
99
-    {
100
-        $this->async = $async;
101
-        return $this;
102
-    }
103
-
104
-    /**
105
-     * @inheritdoc
106
-     */
107
-    public function getAsync(): bool
108
-    {
109
-        return $this->async;
110
-    }
111
-
112
-    /**
113
-     * @inheritdoc
114
-     */
115
-    public function setElasticMetaHeader(bool $active): self
116
-    {
117
-        $this->elasticMetaHeader = $active;
118
-        return $this;
119
-    }
120
-
121
-    /**
122
-     * @inheritdoc
123
-     */
124
-    public function getElasticMetaHeader(): bool
125
-    {
126
-        return $this->elasticMetaHeader;
127
-    }
128
-
129
-    /**
130
-     * @inheritdoc
131
-     */
132
-    public function setResponseException(bool $active): self
133
-    {
134
-        $this->responseException = $active;
135
-        return $this;
136
-    }
137
-
138
-    /**
139
-     * @inheritdoc
140
-     */
141
-    public function getResponseException(): bool
142
-    {
143
-        return $this->responseException;
144
-    }
145
-
146
-    /**
147
-     * @inheritdoc
148
-     */
149
-    public function sendRequest(RequestInterface $request)
150
-    {   
151
-        // If async returns a Promise
152
-        if ($this->getAsync()) {
153
-            if ($this->getElasticMetaHeader()) {
154
-                $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, true);
155
-            }
156
-            $this->transport->setAsyncOnSuccess(
157
-                $request->getMethod() === 'HEAD'
158
-                    ? new AsyncOnSuccessNoException
159
-                    : ($this->getResponseException() ? new AsyncOnSuccess : new AsyncOnSuccessNoException)
160
-            );
161
-            return $this->transport->sendAsyncRequest($request);
162
-        }     
163
-
164
-        if ($this->getElasticMetaHeader()) {
165
-            $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, false);
166
-        }
167
-        $start = microtime(true);
168
-        $response = $this->transport->sendRequest($request);
169
-        $this->logger->info(sprintf("Response time in %.3f sec", microtime(true) - $start));       
170
-
171
-        $result = new Elasticsearch;
172
-        $result->setResponse($response, $request->getMethod() === 'HEAD' ? false : $this->getResponseException());
173
-        return $result;
174
-    }
68
+		$this->defaultTransportSettings($this->transport);
69
+	}
70
+
71
+	/**
72
+	 * @inheritdoc
73
+	 */
74
+	public function getTransport(): Transport
75
+	{
76
+		return $this->transport;
77
+	}
78
+
79
+	/**
80
+	 * @inheritdoc
81
+	 */
82
+	public function getLogger(): LoggerInterface
83
+	{
84
+		return $this->logger;
85
+	}
86
+
87
+	/**
88
+	 * Set the default settings for Elasticsearch
89
+	 */
90
+	protected function defaultTransportSettings(Transport $transport): void
91
+	{
92
+		$transport->setUserAgent('elasticsearch-php', self::VERSION);
93
+	}
94
+
95
+	/**
96
+	 * @inheritdoc
97
+	 */
98
+	public function setAsync(bool $async): self
99
+	{
100
+		$this->async = $async;
101
+		return $this;
102
+	}
103
+
104
+	/**
105
+	 * @inheritdoc
106
+	 */
107
+	public function getAsync(): bool
108
+	{
109
+		return $this->async;
110
+	}
111
+
112
+	/**
113
+	 * @inheritdoc
114
+	 */
115
+	public function setElasticMetaHeader(bool $active): self
116
+	{
117
+		$this->elasticMetaHeader = $active;
118
+		return $this;
119
+	}
120
+
121
+	/**
122
+	 * @inheritdoc
123
+	 */
124
+	public function getElasticMetaHeader(): bool
125
+	{
126
+		return $this->elasticMetaHeader;
127
+	}
128
+
129
+	/**
130
+	 * @inheritdoc
131
+	 */
132
+	public function setResponseException(bool $active): self
133
+	{
134
+		$this->responseException = $active;
135
+		return $this;
136
+	}
137
+
138
+	/**
139
+	 * @inheritdoc
140
+	 */
141
+	public function getResponseException(): bool
142
+	{
143
+		return $this->responseException;
144
+	}
145
+
146
+	/**
147
+	 * @inheritdoc
148
+	 */
149
+	public function sendRequest(RequestInterface $request)
150
+	{   
151
+		// If async returns a Promise
152
+		if ($this->getAsync()) {
153
+			if ($this->getElasticMetaHeader()) {
154
+				$this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, true);
155
+			}
156
+			$this->transport->setAsyncOnSuccess(
157
+				$request->getMethod() === 'HEAD'
158
+					? new AsyncOnSuccessNoException
159
+					: ($this->getResponseException() ? new AsyncOnSuccess : new AsyncOnSuccessNoException)
160
+			);
161
+			return $this->transport->sendAsyncRequest($request);
162
+		}     
163
+
164
+		if ($this->getElasticMetaHeader()) {
165
+			$this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, false);
166
+		}
167
+		$start = microtime(true);
168
+		$response = $this->transport->sendRequest($request);
169
+		$this->logger->info(sprintf("Response time in %.3f sec", microtime(true) - $start));       
170
+
171
+		$result = new Elasticsearch;
172
+		$result->setResponse($response, $request->getMethod() === 'HEAD' ? false : $this->getResponseException());
173
+		return $result;
174
+	}
175 175
 }
176 176
\ 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
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
  * Elasticsearch B.V licenses this file to you under the MIT License.
11 11
  * See the LICENSE file in the project root for more information.
12 12
  */
13
-declare(strict_types = 1);
13
+declare(strict_types=1);
14 14
 
15 15
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch;
16 16
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,8 +25,7 @@
 block discarded – undo
25 25
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestInterface;
26 26
 use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Log\LoggerInterface;
27 27
 
28
-final class Client implements ClientInterface
29
-{
28
+final class Client implements ClientInterface {
30 29
     const CLIENT_NAME = 'es';
31 30
     const VERSION = '8.13.0';
32 31
     const API_COMPATIBILITY_HEADER = '%s/vnd.elasticsearch+%s; compatible-with=8';
Please login to merge, or discard this patch.
lib/Vendor/Elastic/Elasticsearch/Helper/Iterators/SearchHitIterator.php 2 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -22,145 +22,145 @@
 block discarded – undo
22 22
 class SearchHitIterator implements Iterator, Countable
23 23
 {
24 24
 
25
-    /**
26
-     * @var SearchResponseIterator
27
-     */
28
-    private SearchResponseIterator $searchResponses;
29
-
30
-    /**
31
-     * @var int
32
-     */
33
-    protected int $currentKey;
34
-
35
-    /**
36
-     * @var int
37
-     */
38
-    protected int $currentHitIndex;
39
-
40
-    /**
41
-     * @var array|null
42
-     */
43
-    protected ?array $currentHitData;
44
-
45
-    /**
46
-     * @var int
47
-     */
48
-    protected int $count = 0;
49
-
50
-    /**
51
-     * Constructor
52
-     *
53
-     * @param SearchResponseIterator $searchResponses
54
-     */
55
-    public function __construct(SearchResponseIterator $searchResponses)
56
-    {
57
-        $this->searchResponses = $searchResponses;
58
-    }
59
-
60
-    /**
61
-     * Rewinds the internal SearchResponseIterator and itself
62
-     *
63
-     * @return void
64
-     * @throws ClientResponseException
65
-     * @throws ServerResponseException
66
-     * @see    Iterator::rewind()
67
-     */
68
-    public function rewind(): void
69
-    {
70
-        $this->currentKey = 0;
71
-        $this->searchResponses->rewind();
72
-
73
-        // The first page may be empty. In that case, the next page is fetched.
74
-        $currentPage = $this->searchResponses->current();
75
-        if ($this->searchResponses->valid() && empty($currentPage['hits']['hits'])) {
76
-            $this->searchResponses->next();
77
-        }
78
-
79
-        $this->count = 0;
80
-        if (isset($currentPage['hits']['total']['value'], $currentPage['hits']['total'])) {
81
-            $this->count = $currentPage['hits']['total']['value'] ?? $currentPage['hits']['total'];
82
-        }
83
-
84
-        $this->readPageData();
85
-    }
86
-
87
-    /**
88
-     * Advances pointer of the current hit to the next one in the current page. If there
89
-     * isn't a next hit in the current page, then it advances the current page and moves the
90
-     * pointer to the first hit in the page.
91
-     *
92
-     * @return void
93
-     * @throws ClientResponseException
94
-     * @throws ServerResponseException
95
-     * @see    Iterator::next()
96
-     */
97
-    public function next(): void
98
-    {
99
-        $this->currentKey++;
100
-        $this->currentHitIndex++;
101
-        $currentPage = $this->searchResponses->current();
102
-        if (isset($currentPage['hits']['hits'][$this->currentHitIndex])) {
103
-            $this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
104
-        } else {
105
-            $this->searchResponses->next();
106
-            $this->readPageData();
107
-        }
108
-    }
109
-
110
-    /**
111
-     * Returns a boolean indicating whether or not the current pointer has valid data
112
-     *
113
-     * @return bool
114
-     * @see    Iterator::valid()
115
-     */
116
-    public function valid(): bool
117
-    {
118
-        return is_array($this->currentHitData);
119
-    }
120
-
121
-    /**
122
-     * Returns the current hit
123
-     *
124
-     * @return array
125
-     * @see    Iterator::current()
126
-     */
127
-    public function current(): array
128
-    {
129
-        return $this->currentHitData;
130
-    }
131
-
132
-    /**
133
-     * Returns the current hit index. The hit index spans all pages.
134
-     *
135
-     * @return int
136
-     * @see    Iterator::key()
137
-     */
138
-    public function key(): int
139
-    {
140
-        return $this->currentKey;
141
-    }
142
-
143
-    /**
144
-     * Advances the internal SearchResponseIterator and resets the currentHitIndex to 0
145
-     *
146
-     * @internal
147
-     */
148
-    private function readPageData(): void
149
-    {
150
-        if ($this->searchResponses->valid()) {
151
-            $currentPage = $this->searchResponses->current();
152
-            $this->currentHitIndex = 0;
153
-            $this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
154
-        } else {
155
-            $this->currentHitData = null;
156
-        }
157
-    }
158
-
159
-    /**
160
-     * {@inheritDoc}
161
-     */
162
-    public function count(): int
163
-    {
164
-        return $this->count;
165
-    }
25
+	/**
26
+	 * @var SearchResponseIterator
27
+	 */
28
+	private SearchResponseIterator $searchResponses;
29
+
30
+	/**
31
+	 * @var int
32
+	 */
33
+	protected int $currentKey;
34
+
35
+	/**
36
+	 * @var int
37
+	 */
38
+	protected int $currentHitIndex;
39
+
40
+	/**
41
+	 * @var array|null
42
+	 */
43
+	protected ?array $currentHitData;
44
+
45
+	/**
46
+	 * @var int
47
+	 */
48
+	protected int $count = 0;
49
+
50
+	/**
51
+	 * Constructor
52
+	 *
53
+	 * @param SearchResponseIterator $searchResponses
54
+	 */
55
+	public function __construct(SearchResponseIterator $searchResponses)
56
+	{
57
+		$this->searchResponses = $searchResponses;
58
+	}
59
+
60
+	/**
61
+	 * Rewinds the internal SearchResponseIterator and itself
62
+	 *
63
+	 * @return void
64
+	 * @throws ClientResponseException
65
+	 * @throws ServerResponseException
66
+	 * @see    Iterator::rewind()
67
+	 */
68
+	public function rewind(): void
69
+	{
70
+		$this->currentKey = 0;
71
+		$this->searchResponses->rewind();
72
+
73
+		// The first page may be empty. In that case, the next page is fetched.
74
+		$currentPage = $this->searchResponses->current();
75
+		if ($this->searchResponses->valid() && empty($currentPage['hits']['hits'])) {
76
+			$this->searchResponses->next();
77
+		}
78
+
79
+		$this->count = 0;
80
+		if (isset($currentPage['hits']['total']['value'], $currentPage['hits']['total'])) {
81
+			$this->count = $currentPage['hits']['total']['value'] ?? $currentPage['hits']['total'];
82
+		}
83
+
84
+		$this->readPageData();
85
+	}
86
+
87
+	/**
88
+	 * Advances pointer of the current hit to the next one in the current page. If there
89
+	 * isn't a next hit in the current page, then it advances the current page and moves the
90
+	 * pointer to the first hit in the page.
91
+	 *
92
+	 * @return void
93
+	 * @throws ClientResponseException
94
+	 * @throws ServerResponseException
95
+	 * @see    Iterator::next()
96
+	 */
97
+	public function next(): void
98
+	{
99
+		$this->currentKey++;
100
+		$this->currentHitIndex++;
101
+		$currentPage = $this->searchResponses->current();
102
+		if (isset($currentPage['hits']['hits'][$this->currentHitIndex])) {
103
+			$this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
104
+		} else {
105
+			$this->searchResponses->next();
106
+			$this->readPageData();
107
+		}
108
+	}
109
+
110
+	/**
111
+	 * Returns a boolean indicating whether or not the current pointer has valid data
112
+	 *
113
+	 * @return bool
114
+	 * @see    Iterator::valid()
115
+	 */
116
+	public function valid(): bool
117
+	{
118
+		return is_array($this->currentHitData);
119
+	}
120
+
121
+	/**
122
+	 * Returns the current hit
123
+	 *
124
+	 * @return array
125
+	 * @see    Iterator::current()
126
+	 */
127
+	public function current(): array
128
+	{
129
+		return $this->currentHitData;
130
+	}
131
+
132
+	/**
133
+	 * Returns the current hit index. The hit index spans all pages.
134
+	 *
135
+	 * @return int
136
+	 * @see    Iterator::key()
137
+	 */
138
+	public function key(): int
139
+	{
140
+		return $this->currentKey;
141
+	}
142
+
143
+	/**
144
+	 * Advances the internal SearchResponseIterator and resets the currentHitIndex to 0
145
+	 *
146
+	 * @internal
147
+	 */
148
+	private function readPageData(): void
149
+	{
150
+		if ($this->searchResponses->valid()) {
151
+			$currentPage = $this->searchResponses->current();
152
+			$this->currentHitIndex = 0;
153
+			$this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
154
+		} else {
155
+			$this->currentHitData = null;
156
+		}
157
+	}
158
+
159
+	/**
160
+	 * {@inheritDoc}
161
+	 */
162
+	public function count(): int
163
+	{
164
+		return $this->count;
165
+	}
166 166
 }
167 167
\ 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
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
  * Elasticsearch B.V licenses this file to you under the MIT License.
11 11
  * See the LICENSE file in the project root for more information.
12 12
  */
13
-declare(strict_types = 1);
13
+declare(strict_types=1);
14 14
 
15 15
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Helper\Iterators;
16 16
 
Please login to merge, or discard this patch.
Vendor/Elastic/Elasticsearch/Helper/Iterators/SearchResponseIterator.php 3 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -22,171 +22,171 @@
 block discarded – undo
22 22
 class SearchResponseIterator implements Iterator
23 23
 {
24 24
 
25
-    /**
26
-     * @var ClientInterface
27
-     */
28
-    private ClientInterface $client;
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private array $params;
34
-
35
-    /**
36
-     * @var int
37
-     */
38
-    private int $currentKey = 0;
39
-
40
-    /**
41
-     * @var array
42
-     */
43
-    private array $currentScrolledResponse;
44
-
45
-    /**
46
-     * @var string|null
47
-     */
48
-    private ?string $scrollId;
49
-
50
-    /**
51
-     * @var string duration
52
-     */
53
-    private $scrollTtl;
54
-
55
-    /**
56
-     * Constructor
57
-     *
58
-     * @param ClientInterface $client
59
-     * @param array  $searchParams Associative array of parameters
60
-     * @see   ClientInterface::search()
61
-     */
62
-    public function __construct(ClientInterface $client, array $searchParams)
63
-    {
64
-        $this->client = $client;
65
-        $this->params = $searchParams;
66
-
67
-        if (isset($searchParams['scroll'])) {
68
-            $this->scrollTtl = $searchParams['scroll'];
69
-        }
70
-    }
71
-
72
-    /**
73
-     * Destructor
74
-     *
75
-     * @throws ClientResponseException
76
-     * @throws ServerResponseException
77
-     */
78
-    public function __destruct()
79
-    {
80
-        $this->clearScroll();
81
-    }
82
-
83
-    /**
84
-     * Sets the time to live duration of a scroll window
85
-     *
86
-     * @param  string $timeToLive
87
-     * @return $this
88
-     */
89
-    public function setScrollTimeout(string $timeToLive): SearchResponseIterator
90
-    {
91
-        $this->scrollTtl = $timeToLive;
92
-        return $this;
93
-    }
94
-
95
-    /**
96
-     * Clears the current scroll window if there is a scroll_id stored
97
-     *
98
-     * @return void
99
-     * @throws ClientResponseException
100
-     * @throws ServerResponseException
101
-     */
102
-    private function clearScroll(): void
103
-    {
104
-        if (!empty($this->scrollId)) {
105
-            /* @phpstan-ignore-next-line */
106
-            $this->client->clearScroll(
107
-                [
108
-                    'body' => [
109
-                        'scroll_id' => $this->scrollId
110
-                    ],
111
-                    'client' => [
112
-                        'ignore' => 404
113
-                    ]
114
-                ]
115
-            );
116
-            $this->scrollId = null;
117
-        }
118
-    }
119
-
120
-    /**
121
-     * Rewinds the iterator by performing the initial search.
122
-     *
123
-     * @return void
124
-     * @throws ClientResponseException
125
-     * @throws ServerResponseException
126
-     * @see    Iterator::rewind()
127
-     */
128
-    public function rewind(): void
129
-    {
130
-        $this->clearScroll();
131
-        $this->currentKey = 0;
132
-        /* @phpstan-ignore-next-line */
133
-        $this->currentScrolledResponse = $this->client->search($this->params)->asArray();
134
-        $this->scrollId = $this->currentScrolledResponse['_scroll_id'];
135
-    }
136
-
137
-    /**
138
-     * Fetches every "page" after the first one using the lastest "scroll_id"
139
-     *
140
-     * @return void
141
-     * @throws ClientResponseException
142
-     * @throws ServerResponseException
143
-     * @see    Iterator::next()
144
-     */
145
-    public function next(): void
146
-    {
147
-        /* @phpstan-ignore-next-line */
148
-        $this->currentScrolledResponse = $this->client->scroll(
149
-            [
150
-                'body' => [
151
-                    'scroll_id' => $this->scrollId,
152
-                    'scroll'    => $this->scrollTtl
153
-                ]
154
-            ]
155
-        )->asArray();
156
-        $this->scrollId = $this->currentScrolledResponse['_scroll_id'];
157
-        $this->currentKey++;
158
-    }
159
-
160
-    /**
161
-     * Returns a boolean value indicating if the current page is valid or not
162
-     *
163
-     * @return bool
164
-     * @see    Iterator::valid()
165
-     */
166
-    public function valid(): bool
167
-    {
168
-        return isset($this->currentScrolledResponse['hits']['hits'][0]);
169
-    }
170
-
171
-    /**
172
-     * Returns the current "page"
173
-     *
174
-     * @return array
175
-     * @see    Iterator::current()
176
-     */
177
-    public function current(): array
178
-    {
179
-        return $this->currentScrolledResponse;
180
-    }
181
-
182
-    /**
183
-     * Returns the current "page number" of the current "page"
184
-     *
185
-     * @return int
186
-     * @see    Iterator::key()
187
-     */
188
-    public function key(): int
189
-    {
190
-        return $this->currentKey;
191
-    }
25
+	/**
26
+	 * @var ClientInterface
27
+	 */
28
+	private ClientInterface $client;
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private array $params;
34
+
35
+	/**
36
+	 * @var int
37
+	 */
38
+	private int $currentKey = 0;
39
+
40
+	/**
41
+	 * @var array
42
+	 */
43
+	private array $currentScrolledResponse;
44
+
45
+	/**
46
+	 * @var string|null
47
+	 */
48
+	private ?string $scrollId;
49
+
50
+	/**
51
+	 * @var string duration
52
+	 */
53
+	private $scrollTtl;
54
+
55
+	/**
56
+	 * Constructor
57
+	 *
58
+	 * @param ClientInterface $client
59
+	 * @param array  $searchParams Associative array of parameters
60
+	 * @see   ClientInterface::search()
61
+	 */
62
+	public function __construct(ClientInterface $client, array $searchParams)
63
+	{
64
+		$this->client = $client;
65
+		$this->params = $searchParams;
66
+
67
+		if (isset($searchParams['scroll'])) {
68
+			$this->scrollTtl = $searchParams['scroll'];
69
+		}
70
+	}
71
+
72
+	/**
73
+	 * Destructor
74
+	 *
75
+	 * @throws ClientResponseException
76
+	 * @throws ServerResponseException
77
+	 */
78
+	public function __destruct()
79
+	{
80
+		$this->clearScroll();
81
+	}
82
+
83
+	/**
84
+	 * Sets the time to live duration of a scroll window
85
+	 *
86
+	 * @param  string $timeToLive
87
+	 * @return $this
88
+	 */
89
+	public function setScrollTimeout(string $timeToLive): SearchResponseIterator
90
+	{
91
+		$this->scrollTtl = $timeToLive;
92
+		return $this;
93
+	}
94
+
95
+	/**
96
+	 * Clears the current scroll window if there is a scroll_id stored
97
+	 *
98
+	 * @return void
99
+	 * @throws ClientResponseException
100
+	 * @throws ServerResponseException
101
+	 */
102
+	private function clearScroll(): void
103
+	{
104
+		if (!empty($this->scrollId)) {
105
+			/* @phpstan-ignore-next-line */
106
+			$this->client->clearScroll(
107
+				[
108
+					'body' => [
109
+						'scroll_id' => $this->scrollId
110
+					],
111
+					'client' => [
112
+						'ignore' => 404
113
+					]
114
+				]
115
+			);
116
+			$this->scrollId = null;
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * Rewinds the iterator by performing the initial search.
122
+	 *
123
+	 * @return void
124
+	 * @throws ClientResponseException
125
+	 * @throws ServerResponseException
126
+	 * @see    Iterator::rewind()
127
+	 */
128
+	public function rewind(): void
129
+	{
130
+		$this->clearScroll();
131
+		$this->currentKey = 0;
132
+		/* @phpstan-ignore-next-line */
133
+		$this->currentScrolledResponse = $this->client->search($this->params)->asArray();
134
+		$this->scrollId = $this->currentScrolledResponse['_scroll_id'];
135
+	}
136
+
137
+	/**
138
+	 * Fetches every "page" after the first one using the lastest "scroll_id"
139
+	 *
140
+	 * @return void
141
+	 * @throws ClientResponseException
142
+	 * @throws ServerResponseException
143
+	 * @see    Iterator::next()
144
+	 */
145
+	public function next(): void
146
+	{
147
+		/* @phpstan-ignore-next-line */
148
+		$this->currentScrolledResponse = $this->client->scroll(
149
+			[
150
+				'body' => [
151
+					'scroll_id' => $this->scrollId,
152
+					'scroll'    => $this->scrollTtl
153
+				]
154
+			]
155
+		)->asArray();
156
+		$this->scrollId = $this->currentScrolledResponse['_scroll_id'];
157
+		$this->currentKey++;
158
+	}
159
+
160
+	/**
161
+	 * Returns a boolean value indicating if the current page is valid or not
162
+	 *
163
+	 * @return bool
164
+	 * @see    Iterator::valid()
165
+	 */
166
+	public function valid(): bool
167
+	{
168
+		return isset($this->currentScrolledResponse['hits']['hits'][0]);
169
+	}
170
+
171
+	/**
172
+	 * Returns the current "page"
173
+	 *
174
+	 * @return array
175
+	 * @see    Iterator::current()
176
+	 */
177
+	public function current(): array
178
+	{
179
+		return $this->currentScrolledResponse;
180
+	}
181
+
182
+	/**
183
+	 * Returns the current "page number" of the current "page"
184
+	 *
185
+	 * @return int
186
+	 * @see    Iterator::key()
187
+	 */
188
+	public function key(): int
189
+	{
190
+		return $this->currentKey;
191
+	}
192 192
 }
193 193
\ 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
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
  * Elasticsearch B.V licenses this file to you under the MIT License.
11 11
  * See the LICENSE file in the project root for more information.
12 12
  */
13
-declare(strict_types = 1);
13
+declare(strict_types=1);
14 14
 
15 15
 namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Helper\Iterators;
16 16
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,7 @@
 block discarded – undo
19 19
 use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Exception\ServerResponseException;
20 20
 use Iterator;
21 21
 
22
-class SearchResponseIterator implements Iterator
23
-{
22
+class SearchResponseIterator implements Iterator {
24 23
 
25 24
     /**
26 25
      * @var ClientInterface
Please login to merge, or discard this patch.