Skip to content

Commit 34b44d7

Browse files
author
Martin Brecht-Precht
committed
Removed exceptions and use markenwerk/common-exceptions instead.
1 parent d96cd25 commit 34b44d7

12 files changed

+43
-81
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"require": {
2525
"php": ">=5.3",
26+
"markenwerk/common-exceptions": "*",
2627
"markenwerk/google-datastructures": "*"
2728
},
2829
"require-dev":{

src/AddressLookup.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace GoogleGeocode;
44

5+
use CommonException;
6+
57
/**
68
* Class AddressLookup
79
*
@@ -13,10 +15,10 @@ class AddressLookup extends Base\BaseLookup
1315
/**
1416
* @param string $address
1517
* @return $this
16-
* @throws Exception\ApiException
17-
* @throws Exception\ApiLimitException
18-
* @throws Exception\ApiNoResultsException
19-
* @throws Exception\NetworkException
18+
* @throws CommonException\ApiException\ApiException
19+
* @throws CommonException\ApiException\ApiLimitException
20+
* @throws CommonException\ApiException\ApiNoResultsException
21+
* @throws CommonException\ApiException\NetworkException
2022
*/
2123
public function lookup($address)
2224
{

src/Base/BaseLookup.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace GoogleGeocode\Base;
44

5+
use CommonException;
56
use GoogleGeocode;
67
use GoogleDataStructure;
78

@@ -71,10 +72,10 @@ public function getFirstResult()
7172
*
7273
* @param string
7374
* @return string
74-
* @throws GoogleGeocode\Exception\ApiException
75-
* @throws GoogleGeocode\Exception\ApiLimitException
76-
* @throws GoogleGeocode\Exception\ApiNoResultsException
77-
* @throws GoogleGeocode\Exception\NetworkException
75+
* @throws CommonException\ApiException\ApiException
76+
* @throws CommonException\ApiException\ApiLimitException
77+
* @throws CommonException\ApiException\ApiNoResultsException
78+
* @throws CommonException\ApiException\NetworkException
7879
*/
7980
protected function request($url)
8081
{
@@ -84,7 +85,7 @@ protected function request($url)
8485
$response = curl_exec($curl);
8586
curl_close($curl);
8687
if (!$response) {
87-
throw new GoogleGeocode\Exception\NetworkException('Curling the API endpoint ' . $url . ' failed.');
88+
throw new CommonException\ApiException\NetworkException('Curling the API endpoint ' . $url . ' failed.');
8889
}
8990
$responseData = @json_decode($response, true);
9091
$this->validateResponse($response, $responseData);
@@ -94,26 +95,26 @@ protected function request($url)
9495
/**
9596
* @param string $rawResponse
9697
* @param array|string $responseData
97-
* @throws GoogleGeocode\Exception\ApiException
98-
* @throws GoogleGeocode\Exception\ApiLimitException
99-
* @throws GoogleGeocode\Exception\ApiNoResultsException
98+
* @throws CommonException\ApiException\ApiException
99+
* @throws CommonException\ApiException\ApiLimitException
100+
* @throws CommonException\ApiException\ApiNoResultsException
100101
*/
101102
private function validateResponse($rawResponse, $responseData)
102103
{
103104
if (is_null($responseData) || !is_array($responseData) || !isset($responseData['status'])) {
104-
throw new GoogleGeocode\Exception\ApiException('Parsing the API response from body failed: ' . $rawResponse);
105+
throw new CommonException\ApiException\ApiException('Parsing the API response from body failed: ' . $rawResponse);
105106
}
106107

107108
$responseStatus = mb_strtoupper($responseData['status']);
108109
if ($responseStatus == 'OVER_QUERY_LIMIT') {
109110
$exceptionMessage = $this->buildExceptionMessage('Google Geocoder request limit reached', $responseData);
110-
throw new GoogleGeocode\Exception\ApiLimitException($exceptionMessage);
111+
throw new CommonException\ApiException\ApiLimitException($exceptionMessage);
111112
} else if ($responseStatus == 'REQUEST_DENIED') {
112113
$exceptionMessage = $this->buildExceptionMessage('Google Geocoder request was denied', $responseData);
113-
throw new GoogleGeocode\Exception\ApiException($exceptionMessage);
114+
throw new CommonException\ApiException\ApiException($exceptionMessage);
114115
} else if ($responseStatus != 'OK') {
115116
$exceptionMessage = $this->buildExceptionMessage('Google Geocoder no results', $responseData);
116-
throw new GoogleGeocode\Exception\ApiNoResultsException($exceptionMessage);
117+
throw new CommonException\ApiException\ApiNoResultsException($exceptionMessage);
117118
}
118119
}
119120

src/Exception/ApiException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Exception/ApiLimitException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Exception/ApiNoResultsException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Exception/NetworkException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/GeoLocationLookup.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace GoogleGeocode;
44

5+
use CommonException;
6+
57
/**
68
* Class GeoLocationLookup
79
*
@@ -14,10 +16,10 @@ class GeoLocationLookup extends Base\BaseLookup
1416
* @param float $latitude
1517
* @param float $longitude
1618
* @return $this
17-
* @throws Exception\ApiException
18-
* @throws Exception\ApiLimitException
19-
* @throws Exception\ApiNoResultsException
20-
* @throws Exception\NetworkException
19+
* @throws CommonException\ApiException\ApiException
20+
* @throws CommonException\ApiException\ApiLimitException
21+
* @throws CommonException\ApiException\ApiNoResultsException
22+
* @throws CommonException\ApiException\NetworkException
2123
*/
2224
public function lookup($latitude, $longitude)
2325
{

src/GooglePlacesLookup.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace GoogleGeocode;
44

5+
use CommonException;
6+
57
/**
68
* Class GooglePlacesLookup
79
*
@@ -13,10 +15,10 @@ class GooglePlacesLookup extends Base\BaseApiKeyGatedLookup
1315
/**
1416
* @param string $googlePlacesId
1517
* @return $this
16-
* @throws Exception\ApiException
17-
* @throws Exception\ApiLimitException
18-
* @throws Exception\ApiNoResultsException
19-
* @throws Exception\NetworkException
18+
* @throws CommonException\ApiException\ApiException
19+
* @throws CommonException\ApiException\ApiLimitException
20+
* @throws CommonException\ApiException\ApiNoResultsException
21+
* @throws CommonException\ApiException\NetworkException
2022
*/
2123
public function lookup($googlePlacesId)
2224
{

test/AddressLookupTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace GoogleGeocode;
44

5+
use CommonException;
6+
57
/**
68
* Class AddressLookupTest
79
*
@@ -20,7 +22,7 @@ public function testLookupSuccess()
2022
$this->assertEquals(1, $addressLookup->getResultCount());
2123
$firstResult = $addressLookup->getFirstResult();
2224
$this->assertInstanceOf('GoogleGeocode\\GeoLookupResult', $firstResult);
23-
print_r($firstResult);
25+
2426
// Address result
2527
$this->assertTrue($firstResult->hasAddress());
2628
$addressResult = $firstResult->getAddress();
@@ -72,7 +74,7 @@ public function testLookupSuccess()
7274

7375
public function testLookupFailure()
7476
{
75-
$this->setExpectedException(get_class(new Exception\ApiNoResultsException()));
77+
$this->setExpectedException(get_class(new CommonException\ApiException\ApiNoResultsException()));
7678
$addressLookup = new AddressLookup();
7779
$addressLookup->lookup('China, Bejing, Lornsenstraße 43');
7880
}

0 commit comments

Comments
 (0)