Skip to content

Commit 4d267e8

Browse files
committed
Merge pull request #248 from Baachi/limit
Add limit/setMaxResults method
2 parents 94a4315 + 6d89d5b commit 4d267e8

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

src/Geocoder/Geocoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(ProviderInterface $provider = null, ResultFactoryInt
6060
$this->provider = $provider;
6161

6262
$this->setResultFactory($resultFactory);
63-
$this->setMaxResults($maxResults);
63+
$this->limit($maxResults);
6464
}
6565

6666
/**
@@ -76,7 +76,7 @@ public function setResultFactory(ResultFactoryInterface $resultFactory = null)
7676
*
7777
* @return GeocoderInterface
7878
*/
79-
public function setMaxResults($maxResults)
79+
public function limit($maxResults)
8080
{
8181
$this->maxResults = $maxResults;
8282

src/Geocoder/Provider/AbstractProvider.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ public function setLocale($locale = null)
9292
}
9393

9494
/**
95-
* Sets the maximum of returned results.
96-
*
97-
* @param integer $maxResults
98-
*
99-
* @return AbstractProvider
95+
* {@inheritDoc}
10096
*/
10197
public function setMaxResults($maxResults)
10298
{

src/Geocoder/Provider/ChainProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public function getReversedData(array $coordinates)
7777
throw new NoResultException(sprintf('No provider could provide the coordinated %s', json_encode($coordinates)));
7878
}
7979

80+
/**
81+
* {@inheritDoc}
82+
*/
83+
public function setMaxResults($limit)
84+
{
85+
foreach ($this->providers as $provider) {
86+
$provider->setMaxResults($limit);
87+
}
88+
89+
return $this;
90+
}
91+
8092
/**
8193
* {@inheritDoc}
8294
*/

src/Geocoder/Provider/ProviderInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function getReversedData(array $coordinates);
5151
* @return string
5252
*/
5353
public function getName();
54+
55+
/**
56+
* Sets the maximum of returned results.
57+
*
58+
* @param integer $limit
59+
*
60+
* @return ProviderInterface
61+
*/
62+
public function setMaxResults($limit);
5463
}

tests/Geocoder/Tests/GeocoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testSetAndUseCustomMultipleResultFactory()
202202

203203
public function testSetMaxResults()
204204
{
205-
$this->geocoder->setMaxResults(3);
205+
$this->geocoder->limit(3);
206206
$this->assertSame(3, $this->geocoder->getMaxResults());
207207
}
208208

0 commit comments

Comments
 (0)