Skip to content

Commit 77c4681

Browse files
authored
Remove deprecated code (#678)
* Removed LocationFactory * Removed `returnResults` * Added default Location for localhost * Removed getDefaults * Added class comment * cs * Make sure to transform the country code
1 parent 6030a73 commit 77c4681

File tree

13 files changed

+39
-316
lines changed

13 files changed

+39
-316
lines changed

Formatter/StringFormatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,18 @@ class StringFormatter
5050
*/
5151
public function format(Location $location, $format)
5252
{
53+
if (null !== $code = $location->getCountry()->getCode()) {
54+
$code = strtoupper($code);
55+
}
56+
5357
$replace = [
5458
self::STREET_NUMBER => $location->getStreetNumber(),
5559
self::STREET_NAME => $location->getStreetName(),
5660
self::LOCALITY => $location->getLocality(),
5761
self::POSTAL_CODE => $location->getPostalCode(),
5862
self::SUB_LOCALITY => $location->getSubLocality(),
5963
self::COUNTRY => $location->getCountry()->getName(),
60-
self::COUNTRY_CODE => $location->getCountry()->getCode(),
64+
self::COUNTRY_CODE => $code,
6165
self::TIMEZONE => $location->getTimezone(),
6266
];
6367

Model/LocationFactory.php

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

Provider/AbstractHttpProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/**
2323
* @author William Durand <william.durand1@gmail.com>
24+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2425
*/
2526
abstract class AbstractHttpProvider extends AbstractProvider
2627
{

Provider/AbstractProvider.php

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,24 @@
1313
namespace Geocoder\Provider;
1414

1515
use Geocoder\Geocoder;
16-
use Geocoder\Collection;
17-
use Geocoder\Model\AddressCollection;
18-
use Geocoder\Model\LocationFactory;
16+
use Geocoder\Location;
17+
use Geocoder\Model\Address;
1918

2019
/**
2120
* @author William Durand <william.durand1@gmail.com>
2221
*/
2322
abstract class AbstractProvider
2423
{
25-
/**
26-
* Returns the default results.
27-
*
28-
* @return array
29-
*
30-
* @deprecated Use LocationBuilder
31-
*/
32-
protected function getDefaults()
33-
{
34-
return [
35-
'latitude' => null,
36-
'longitude' => null,
37-
'bounds' => [
38-
'south' => null,
39-
'west' => null,
40-
'north' => null,
41-
'east' => null,
42-
],
43-
'streetNumber' => null,
44-
'streetName' => null,
45-
'locality' => null,
46-
'postalCode' => null,
47-
'subLocality' => null,
48-
'adminLevels' => [],
49-
'country' => null,
50-
'countryCode' => null,
51-
'timezone' => null,
52-
];
53-
}
54-
5524
/**
5625
* Returns the results for the 'localhost' special case.
5726
*
58-
* @return array
59-
*
60-
* @deprecated
27+
* @return Location
6128
*/
62-
protected function getLocalhostDefaults()
29+
protected function getLocationForLocalhost()
6330
{
64-
return [
31+
return Address::createFromArray([
6532
'locality' => 'localhost',
6633
'country' => 'localhost',
67-
];
68-
}
69-
70-
/**
71-
* @param array $data an array of data
72-
*
73-
* @return Collection
74-
*
75-
* @deprecated Use the AddressBuilder
76-
*/
77-
protected function returnResults(array $data = [])
78-
{
79-
$addresses = [];
80-
foreach ($data as $result) {
81-
$addresses[] = LocationFactory::createLocation($result);
82-
}
83-
84-
return new AddressCollection($addresses);
34+
]);
8535
}
8636
}

Tests/Dumper/GeoArrayTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Geocoder\Tests\Dumper;
1414

1515
use Geocoder\Dumper\GeoArray;
16-
use Geocoder\Model\LocationFactory;
16+
use Geocoder\Model\Address;
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
@@ -33,7 +33,7 @@ protected function setUp()
3333

3434
public function testDump()
3535
{
36-
$address = LocationFactory::createLocation([]);
36+
$address = Address::createFromArray([]);
3737
$expected = [
3838
'type' => 'Feature',
3939
'geometry' => [
@@ -53,7 +53,7 @@ public function testDump()
5353

5454
public function testDumpWithData()
5555
{
56-
$address = LocationFactory::createLocation([
56+
$address = Address::createFromArray([
5757
'latitude' => 48.8631507,
5858
'longitude' => 2.3889114,
5959
]);
@@ -77,7 +77,7 @@ public function testDumpWithData()
7777

7878
public function testDumpWithBounds()
7979
{
80-
$address = LocationFactory::createLocation([
80+
$address = Address::createFromArray([
8181
'latitude' => 48.8631507,
8282
'longitude' => 2.3889114,
8383
'bounds' => [
@@ -113,7 +113,7 @@ public function testDumpWithBounds()
113113

114114
public function testDumpWithProperties()
115115
{
116-
$address = LocationFactory::createLocation([
116+
$address = Address::createFromArray([
117117
'latitude' => 48.8631507,
118118
'longitude' => 2.3889114,
119119
'bounds' => [

Tests/Dumper/GeoJsonTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Geocoder\Tests\Dumper;
1414

1515
use Geocoder\Dumper\GeoJson;
16-
use Geocoder\Model\LocationFactory;
16+
use Geocoder\Model\Address;
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
@@ -34,7 +34,7 @@ public function setUp()
3434

3535
public function testDump()
3636
{
37-
$address = LocationFactory::createLocation([]);
37+
$address = Address::createFromArray([]);
3838
$expected = [
3939
'type' => 'Feature',
4040
'geometry' => [
@@ -54,7 +54,7 @@ public function testDump()
5454

5555
public function testDumpWithData()
5656
{
57-
$address = LocationFactory::createLocation([
57+
$address = Address::createFromArray([
5858
'latitude' => 48.8631507,
5959
'longitude' => 2.3889114,
6060
]);
@@ -78,7 +78,7 @@ public function testDumpWithData()
7878

7979
public function testDumpWithBounds()
8080
{
81-
$address = LocationFactory::createLocation([
81+
$address = Address::createFromArray([
8282
'latitude' => 48.8631507,
8383
'longitude' => 2.3889114,
8484
'bounds' => [
@@ -114,7 +114,7 @@ public function testDumpWithBounds()
114114

115115
public function testDumpWithProperties()
116116
{
117-
$address = LocationFactory::createLocation([
117+
$address = Address::createFromArray([
118118
'latitude' => 48.8631507,
119119
'longitude' => 2.3889114,
120120
'bounds' => [

0 commit comments

Comments
 (0)