Skip to content

Commit c6d684d

Browse files
authored
Merge pull request #1773 from deguif/master
Add return type-hint to result classes
2 parents beabcf3 + edfbcad commit c6d684d

File tree

6 files changed

+17
-28
lines changed

6 files changed

+17
-28
lines changed

CHANGELOG-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ in 6.0 versions.
1818
* **[BC break]** Marked all events final and introduced several abstract classes.
1919
* **[BC break]** Signature of `FantaPaginatorAdapter::getNbResults()` has changed.
2020
* **[BC break]** Signature of `FantaPaginatorAdapter::getSlice()` has changed.
21+
* **[BC break]** Signature of `PartialResultsInterface::toArray()`, `PartialResultsInterface::getTotalHits()` and `PartialResultsInterface::getAggregations()` have changed.
2122

2223
### 6.0.0-BETA3 (2020-09-28)
2324

src/Paginator/HybridPartialResults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInte
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function toArray()
37+
public function toArray(): array
3838
{
3939
return $this->transformer->hybridTransform($this->resultSet->getResults());
4040
}

src/Paginator/PartialResultsInterface.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,16 @@ interface PartialResultsInterface
1515
{
1616
/**
1717
* Returns the paginated results.
18-
*
19-
* @return array
2018
*/
21-
public function toArray();
19+
public function toArray(): array;
2220

2321
/**
2422
* Returns the number of results.
25-
*
26-
* @return int The number of results
2723
*/
28-
public function getTotalHits();
24+
public function getTotalHits(): int;
2925

3026
/**
3127
* Returns the aggregations.
32-
*
33-
* @return array
3428
*/
35-
public function getAggregations();
29+
public function getAggregations(): array;
3630
}

src/Paginator/RawPartialResults.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(ResultSet $resultSet)
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function toArray()
32+
public function toArray(): array
3333
{
3434
return \array_map(function (Result $result) {
3535
return $result->getSource();
@@ -39,32 +39,21 @@ public function toArray()
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function getTotalHits()
42+
public function getTotalHits(): int
4343
{
4444
return $this->resultSet->getTotalHits();
4545
}
4646

4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function getAggregations()
50+
public function getAggregations(): array
5151
{
52-
if ($this->resultSet->hasAggregations()) {
53-
return $this->resultSet->getAggregations();
54-
}
55-
56-
return;
52+
return $this->resultSet->getAggregations();
5753
}
5854

59-
/**
60-
* {@inheritdoc}
61-
*/
62-
public function getSuggests()
55+
public function getSuggests(): array
6356
{
64-
if ($this->resultSet->hasSuggests()) {
65-
return $this->resultSet->getSuggests();
66-
}
67-
68-
return;
57+
return $this->resultSet->getSuggests();
6958
}
7059
}

src/Paginator/TransformedPartialResults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInte
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function toArray()
34+
public function toArray(): array
3535
{
3636
return $this->transformer->transform($this->resultSet->getResults());
3737
}

tests/Unit/Paginator/HybridPartialResultsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class HybridPartialResultsTest extends UnitTestHelper
2020
public function testToArray()
2121
{
2222
$transformer = $this->mockElasticaToModelTransformer();
23+
$transformer
24+
->expects($this->once())
25+
->method('hybridTransform')
26+
->willReturn([])
27+
;
2328

2429
$resultSet = $this->mockResultSet();
2530

0 commit comments

Comments
 (0)