Skip to content

Commit 045c412

Browse files
committed
Convert all providers as @MattKetmo suggested
1 parent 925b4d8 commit 045c412

21 files changed

+42
-88
lines changed

src/Geocoder/Provider/AbstractProvider.php

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ abstract class AbstractProvider
4545
*/
4646
public function __construct(HttpAdapterInterface $adapter, $locale = null)
4747
{
48-
$this->setAdapter($adapter);
4948
$this->setLocale($locale);
50-
$this->factory = new AddressFactory();
49+
50+
$this->adapter = $adapter;
51+
$this->factory = new AddressFactory();
5152
}
5253

5354
/**
@@ -60,40 +61,6 @@ public function getAdapter()
6061
return $this->adapter;
6162
}
6263

63-
/**
64-
* Sets the HTTP adapter to be used for further requests.
65-
*
66-
* @param HttpAdapterInterface $adapter
67-
*
68-
* @return AbstractProvider
69-
*/
70-
public function setAdapter($adapter)
71-
{
72-
$this->adapter = $adapter;
73-
74-
return $this;
75-
}
76-
77-
/**
78-
* Returns the configured locale or null.
79-
*
80-
* @return string
81-
*/
82-
public function getLocale()
83-
{
84-
return $this->locale;
85-
}
86-
87-
/**
88-
* {@inheritDoc}
89-
*/
90-
public function setLocale($locale = null)
91-
{
92-
$this->locale = $locale;
93-
94-
return $this;
95-
}
96-
9764
/**
9865
* {@inheritDoc}
9966
*/

src/Geocoder/Provider/ArcGISOnline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(HttpAdapterInterface $adapter, $sourceCountry = null
5555
/**
5656
* {@inheritDoc}
5757
*/
58-
public function getGeocodedData($address)
58+
public function geocode($address)
5959
{
6060
if (filter_var($address, FILTER_VALIDATE_IP)) {
6161
throw new UnsupportedOperation('The ArcGISOnline does not support IP addresses.');
@@ -108,7 +108,7 @@ public function getGeocodedData($address)
108108
/**
109109
* {@inheritDoc}
110110
*/
111-
public function getReversedData(array $coordinates)
111+
public function reverse($latitude, $longitude)
112112
{
113113
$query = sprintf(self::REVERSE_ENDPOINT_URL, $this->protocol, $coordinates[1], $coordinates[0]);
114114

src/Geocoder/Provider/BingMaps.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(HttpAdapterInterface $adapter, $apiKey, $locale = nu
5050
/**
5151
* {@inheritDoc}
5252
*/
53-
public function getGeocodedData($address)
53+
public function geocode($address)
5454
{
5555
if (null === $this->apiKey) {
5656
throw new InvalidCredentials('No API Key provided');
@@ -69,7 +69,7 @@ public function getGeocodedData($address)
6969
/**
7070
* {@inheritDoc}
7171
*/
72-
public function getReversedData(array $coordinates)
72+
public function reverse($latitude, $longitude)
7373
{
7474
if (null === $this->apiKey) {
7575
throw new InvalidCredentials('No API Key provided');

src/Geocoder/Provider/Chain.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public function add(Provider $provider)
4646
/**
4747
* {@inheritDoc}
4848
*/
49-
public function getGeocodedData($address)
49+
public function geocode($address)
5050
{
5151
$exceptions = [];
5252

5353
foreach ($this->providers as $provider) {
5454
try {
55-
return $provider->getGeocodedData($address);
55+
return $provider->geocode($address);
5656
} catch (InvalidCredentials $e) {
5757
throw $e;
5858
} catch (\Exception $e) {
@@ -66,7 +66,7 @@ public function getGeocodedData($address)
6666
/**
6767
* {@inheritDoc}
6868
*/
69-
public function getReversedData(array $coordinates)
69+
public function reverse($latitude, $longitude)
7070
{
7171
$exceptions = [];
7272
foreach ($this->providers as $provider) {

src/Geocoder/Provider/FreeGeoIp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FreeGeoIp extends AbstractProvider implements Provider
2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function getGeocodedData($address)
29+
public function geocode($address)
3030
{
3131
if (!filter_var($address, FILTER_VALIDATE_IP)) {
3232
throw new UnsupportedOperation('The FreeGeoIp does not support Street addresses.');
@@ -44,7 +44,7 @@ public function getGeocodedData($address)
4444
/**
4545
* {@inheritDoc}
4646
*/
47-
public function getReversedData(array $coordinates)
47+
public function reverse($latitude, $longitude)
4848
{
4949
throw new UnsupportedOperation('The FreeGeoIp is not able to do reverse geocoding.');
5050
}

src/Geocoder/Provider/GeoIP2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(GeoIP2Adapter $adapter, $locale = 'en')
3333
/**
3434
* {@inheritDoc}
3535
*/
36-
public function getGeocodedData($address)
36+
public function geocode($address)
3737
{
3838
if (false === filter_var($address, FILTER_VALIDATE_IP)) {
3939
throw new UnsupportedOperation(sprintf('The %s does not support street addresses.', __CLASS__));
@@ -71,7 +71,7 @@ public function getGeocodedData($address)
7171
/**
7272
* {@inheritDoc}
7373
*/
74-
public function getReversedData(array $coordinates)
74+
public function reverse($latitude, $longitude)
7575
{
7676
throw new UnsupportedOperation(sprintf('The %s is not able to do reverse geocoding.', __CLASS__));
7777
}

src/Geocoder/Provider/GeoIPs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(HttpAdapterInterface $adapter, $apiKey)
5757
/**
5858
* {@inheritDoc}
5959
*/
60-
public function getGeocodedData($address)
60+
public function geocode($address)
6161
{
6262
if (null === $this->apiKey) {
6363
throw new InvalidCredentials('No API Key provided.');
@@ -84,7 +84,7 @@ public function getGeocodedData($address)
8484
/**
8585
* {@inheritDoc}
8686
*/
87-
public function getReversedData(array $coordinates)
87+
public function reverse($latitude, $longitude)
8888
{
8989
throw new UnsupportedOperation('The GeoIPs is not able to do reverse geocoding.');
9090
}

src/Geocoder/Provider/GeoPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GeoPlugin extends AbstractProvider implements Provider
2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function getGeocodedData($address)
29+
public function geocode($address)
3030
{
3131
if (!filter_var($address, FILTER_VALIDATE_IP)) {
3232
throw new UnsupportedOperation('The GeoPlugin does not support street addresses.');
@@ -44,7 +44,7 @@ public function getGeocodedData($address)
4444
/**
4545
* {@inheritDoc}
4646
*/
47-
public function getReversedData(array $coordinates)
47+
public function reverse($latitude, $longitude)
4848
{
4949
throw new UnsupportedOperation('The GeoPlugin is not able to do reverse geocoding.');
5050
}

src/Geocoder/Provider/Geoip.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct()
3434
/**
3535
* {@inheritDoc}
3636
*/
37-
public function getGeocodedData($address)
37+
public function geocode($address)
3838
{
3939
if (!filter_var($address, FILTER_VALIDATE_IP)) {
4040
throw new UnsupportedOperation('The Geoip does not support Street addresses.');
@@ -74,7 +74,7 @@ public function getGeocodedData($address)
7474
/**
7575
* {@inheritDoc}
7676
*/
77-
public function getReversedData(array $coordinates)
77+
public function reverse($latitude, $longitude)
7878
{
7979
throw new UnsupportedOperation('The Geoip is not able to do reverse geocoding.');
8080
}

src/Geocoder/Provider/Geonames.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(HttpAdapterInterface $adapter, $username, $locale =
5050
/**
5151
* {@inheritDoc}
5252
*/
53-
public function getGeocodedData($address)
53+
public function geocode($address)
5454
{
5555
if (null === $this->username) {
5656
throw new InvalidCredentials('No Username provided');
@@ -69,7 +69,7 @@ public function getGeocodedData($address)
6969
/**
7070
* {@inheritDoc}
7171
*/
72-
public function getReversedData(array $coordinates)
72+
public function reverse($latitude, $longitude)
7373
{
7474
if (null === $this->username) {
7575
throw new InvalidCredentials('No Username provided');

0 commit comments

Comments
 (0)