Skip to content

Commit 979e746

Browse files
committed
class property naming changes for iterator classes
1 parent 7be0fa9 commit 979e746

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/Helper/Iterators/SearchHitIterator.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414

1515
namespace Elastic\Elasticsearch\Helper\Iterators;
1616

17+
use Countable;
18+
use Elastic\Elasticsearch\Exception\ClientResponseException;
19+
use Elastic\Elasticsearch\Exception\ServerResponseException;
1720
use Iterator;
1821

19-
class SearchHitIterator implements Iterator, \Countable
22+
class SearchHitIterator implements Iterator, Countable
2023
{
2124

2225
/**
@@ -58,6 +61,8 @@ public function __construct(SearchResponseIterator $searchResponses)
5861
* Rewinds the internal SearchResponseIterator and itself
5962
*
6063
* @return void
64+
* @throws ClientResponseException
65+
* @throws ServerResponseException
6166
* @see Iterator::rewind()
6267
*/
6368
public function rewind(): void
@@ -66,14 +71,14 @@ public function rewind(): void
6671
$this->searchResponses->rewind();
6772

6873
// The first page may be empty. In that case, the next page is fetched.
69-
$current_page = $this->searchResponses->current();
70-
if ($this->searchResponses->valid() && empty($current_page['hits']['hits'])) {
74+
$currentPage = $this->searchResponses->current();
75+
if ($this->searchResponses->valid() && empty($currentPage['hits']['hits'])) {
7176
$this->searchResponses->next();
7277
}
7378

7479
$this->count = 0;
75-
if (isset($current_page['hits']) && isset($current_page['hits']['total'])) {
76-
$this->count = $current_page['hits']['total']['value'] ?? $current_page['hits']['total'];
80+
if (isset($currentPage['hits']['total']['value'], $currentPage['hits']['total'])) {
81+
$this->count = $currentPage['hits']['total']['value'] ?? $currentPage['hits']['total'];
7782
}
7883

7984
$this->readPageData();
@@ -85,15 +90,17 @@ public function rewind(): void
8590
* pointer to the first hit in the page.
8691
*
8792
* @return void
93+
* @throws ClientResponseException
94+
* @throws ServerResponseException
8895
* @see Iterator::next()
8996
*/
9097
public function next(): void
9198
{
9299
$this->currentKey++;
93100
$this->currentHitIndex++;
94-
$current_page = $this->searchResponses->current();
95-
if (isset($current_page['hits']['hits'][$this->currentHitIndex])) {
96-
$this->currentHitData = $current_page['hits']['hits'][$this->currentHitIndex];
101+
$currentPage = $this->searchResponses->current();
102+
if (isset($currentPage['hits']['hits'][$this->currentHitIndex])) {
103+
$this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
97104
} else {
98105
$this->searchResponses->next();
99106
$this->readPageData();
@@ -141,9 +148,9 @@ public function key(): int
141148
private function readPageData(): void
142149
{
143150
if ($this->searchResponses->valid()) {
144-
$current_page = $this->searchResponses->current();
151+
$currentPage = $this->searchResponses->current();
145152
$this->currentHitIndex = 0;
146-
$this->currentHitData = $current_page['hits']['hits'][$this->currentHitIndex];
153+
$this->currentHitData = $currentPage['hits']['hits'][$this->currentHitIndex];
147154
} else {
148155
$this->currentHitData = null;
149156
}

src/Helper/Iterators/SearchResponseIterator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ class SearchResponseIterator implements Iterator
5050
/**
5151
* @var string duration
5252
*/
53-
private $scroll_ttl;
53+
private $scrollTtl;
5454

5555
/**
5656
* Constructor
5757
*
5858
* @param ClientInterface $client
59-
* @param array $search_params Associative array of parameters
59+
* @param array $searchParams Associative array of parameters
6060
* @see ClientInterface::search()
6161
*/
62-
public function __construct(ClientInterface $client, array $search_params)
62+
public function __construct(ClientInterface $client, array $searchParams)
6363
{
6464
$this->client = $client;
65-
$this->params = $search_params;
65+
$this->params = $searchParams;
6666

67-
if (isset($search_params['scroll'])) {
68-
$this->scroll_ttl = $search_params['scroll'];
67+
if (isset($searchParams['scroll'])) {
68+
$this->scrollTtl = $searchParams['scroll'];
6969
}
7070
}
7171

@@ -83,12 +83,12 @@ public function __destruct()
8383
/**
8484
* Sets the time to live duration of a scroll window
8585
*
86-
* @param string $time_to_live
86+
* @param string $timeToLive
8787
* @return $this
8888
*/
89-
public function setScrollTimeout(string $time_to_live): SearchResponseIterator
89+
public function setScrollTimeout(string $timeToLive): SearchResponseIterator
9090
{
91-
$this->scroll_ttl = $time_to_live;
91+
$this->scrollTtl = $timeToLive;
9292
return $this;
9393
}
9494

@@ -136,6 +136,8 @@ public function rewind(): void
136136
* Fetches every "page" after the first one using the lastest "scroll_id"
137137
*
138138
* @return void
139+
* @throws ClientResponseException
140+
* @throws ServerResponseException
139141
* @see Iterator::next()
140142
*/
141143
public function next(): void
@@ -144,7 +146,7 @@ public function next(): void
144146
[
145147
'body' => [
146148
'scroll_id' => $this->scrollId,
147-
'scroll' => $this->scroll_ttl
149+
'scroll' => $this->scrollTtl
148150
]
149151
]
150152
)->asArray();

tests/Helper/Iterators/SearchResponseIteratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testWithNoResults(): void
7474
$this->assertCount(0, $responses);
7575
}
7676

77-
public function testWithHits()
77+
public function testWithHits(): void
7878
{
7979
$search_params = [
8080
'scroll' => '5m',

0 commit comments

Comments
 (0)