Skip to content

Commit dce7f92

Browse files
committed
Creating interfaces to be more SOLID
1 parent 87a0f6d commit dce7f92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+561
-218
lines changed

src/Geocoder/Dumper/Dumper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Geocoder\Dumper;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415

1516
/**
1617
* @author William Durand <[email protected]>
@@ -21,9 +22,9 @@ interface Dumper
2122
* Dumps an `Address` object as a string representation of
2223
* the implemented format.
2324
*
24-
* @param Address $address
25+
* @param Position $address
2526
*
2627
* @return string
2728
*/
28-
public function dump(Address $address);
29+
public function dump(Position $address);
2930
}

src/Geocoder/Dumper/GeoJson.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Geocoder\Dumper;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415

1516
/**
1617
* @author Jan Sorgalla <[email protected]>
@@ -20,7 +21,7 @@ class GeoJson implements Dumper
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public function dump(Address $address)
24+
public function dump(Position $address)
2425
{
2526
$properties = array_filter($address->toArray(), function ($value) {
2627
return !empty($value);

src/Geocoder/Dumper/Gpx.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212

1313
use Geocoder\Geocoder;
1414
use Geocoder\Model\Address;
15+
use Geocoder\Model\Position;
1516

1617
/**
1718
* @author William Durand <[email protected]>
1819
*/
1920
class Gpx implements Dumper
2021
{
2122
/**
22-
* @param Address $address
23+
* @param Position $address
2324
*
2425
* @return string
2526
*/
26-
public function dump(Address $address)
27+
public function dump(Position $address)
2728
{
2829
$gpx = sprintf(<<<GPX
2930
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
@@ -63,11 +64,11 @@ public function dump(Address $address)
6364
}
6465

6566
/**
66-
* @param Address $address
67+
* @param Position $address
6768
*
6869
* @return string
6970
*/
70-
protected function formatName(Address $address)
71+
protected function formatName(Position $address)
7172
{
7273
$name = [];
7374
$array = $address->toArray();

src/Geocoder/Dumper/Kml.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Geocoder\Dumper;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415

1516
/**
1617
* @author Jan Sorgalla <[email protected]>
@@ -20,7 +21,7 @@ class Kml extends Gpx implements Dumper
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public function dump(Address $address)
24+
public function dump(Position $address)
2425
{
2526
$name = $this->formatName($address);
2627
$kml = <<<KML

src/Geocoder/Dumper/Wkb.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Geocoder\Dumper;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415

1516
/**
1617
* @author Jan Sorgalla <[email protected]>
@@ -20,7 +21,7 @@ class Wkb implements Dumper
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public function dump(Address $address)
24+
public function dump(Position $address)
2425
{
2526
return pack('cLdd', 1, 1, $address->getLongitude(), $address->getLatitude());
2627
}

src/Geocoder/Dumper/Wkt.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Geocoder\Dumper;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415

1516
/**
1617
* @author Jan Sorgalla <[email protected]>
@@ -20,7 +21,7 @@ class Wkt implements Dumper
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public function dump(Address $address)
24+
public function dump(Position $address)
2425
{
2526
return sprintf('POINT(%F %F)', $address->getLongitude(), $address->getLatitude());
2627
}

src/Geocoder/Formatter/StringFormatter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
namespace Geocoder\Formatter;
1212

1313
use Geocoder\Model\Address;
14+
use Geocoder\Model\Position;
1415
use Geocoder\Model\AdminLevel;
15-
use Geocoder\Model\AdminLevelCollection;
16+
use Geocoder\Model\AdminLevelCollectionInterface;
1617

1718
/**
1819
* @author William Durand <[email protected]>
@@ -42,12 +43,12 @@ class StringFormatter
4243
/**
4344
* Transform an `Address` instance into a string representation.
4445
*
45-
* @param Address $address
46-
* @param string $format
46+
* @param Position $address
47+
* @param string $format
4748
*
4849
* @return string
4950
*/
50-
public function format(Address $address, $format)
51+
public function format(Position $address, $format)
5152
{
5253
$replace = [
5354
self::STREET_NUMBER => $address->getStreetNumber(),
@@ -60,7 +61,7 @@ public function format(Address $address, $format)
6061
self::TIMEZONE => $address->getTimezone(),
6162
];
6263

63-
for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level ++) {
64+
for ($level = 1; $level <= AdminLevelCollectionInterface::MAX_LEVEL_DEPTH; $level ++) {
6465
$replace[self::ADMIN_LEVEL . $level] = null;
6566
$replace[self::ADMIN_LEVEL_CODE . $level] = null;
6667
}

src/Geocoder/Geocoder.php

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

1111
namespace Geocoder;
1212

13-
use Geocoder\Model\AddressCollection;
14-
1513
/**
1614
* @author William Durand <[email protected]>
1715
*/
@@ -27,7 +25,7 @@ interface Geocoder
2725
*
2826
* @param string $value
2927
*
30-
* @return AddressCollection
28+
* @return GeocoderResult
3129
* @throws \Geocoder\Exception\Exception
3230
*/
3331
public function geocode($value);
@@ -38,7 +36,7 @@ public function geocode($value);
3836
* @param double $latitude
3937
* @param double $longitude
4038
*
41-
* @return AddressCollection
39+
* @return GeocoderResult
4240
* @throws \Geocoder\Exception\Exception
4341
*/
4442
public function reverse($latitude, $longitude);

src/Geocoder/GeocoderResult.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace Geocoder;
3+
4+
use Geocoder\Model\Position;
5+
6+
/**
7+
* This is the interface that is always return from a geocoder.
8+
*/
9+
interface GeocoderResult extends \IteratorAggregate, \Countable
10+
{
11+
/**
12+
* {@inheritDoc}
13+
*/
14+
public function getIterator();
15+
16+
/**
17+
* {@inheritDoc}
18+
*/
19+
public function count();
20+
21+
/**
22+
* @return Position
23+
*/
24+
public function first();
25+
26+
/**
27+
* @return Position[]
28+
*/
29+
public function slice($offset, $length = null);
30+
31+
/**
32+
* @return bool
33+
*/
34+
public function has($index);
35+
36+
/**
37+
* @return Position
38+
* @throws \OutOfBoundsException
39+
*/
40+
public function get($index);
41+
42+
/**
43+
* @return Position[]
44+
*/
45+
public function all();
46+
}

src/Geocoder/Model/Address.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
/**
1414
* @author William Durand <[email protected]>
1515
*/
16-
final class Address
16+
final class Address implements Position
1717
{
1818
/**
19-
* @var Coordinates
19+
* @var CoordinatesInterface
2020
*/
2121
private $coordinates;
2222

2323
/**
24-
* @var Bounds
24+
* @var BoundsInterface
2525
*/
2626
private $bounds;
2727

@@ -51,12 +51,12 @@ final class Address
5151
private $postalCode;
5252

5353
/**
54-
* @var AdminLevelCollection
54+
* @var AdminLevelCollectionInterface
5555
*/
5656
private $adminLevels;
5757

5858
/**
59-
* @var Country
59+
* @var CountryInterface
6060
*/
6161
private $country;
6262

@@ -73,15 +73,15 @@ final class Address
7373
* @param string $subLocality
7474
*/
7575
public function __construct(
76-
Coordinates $coordinates = null,
77-
Bounds $bounds = null,
76+
CoordinatesInterface $coordinates = null,
77+
BoundsInterface $bounds = null,
7878
$streetNumber = null,
7979
$streetName = null,
8080
$postalCode = null,
8181
$locality = null,
8282
$subLocality = null,
83-
AdminLevelCollection $adminLevels = null,
84-
Country $country = null,
83+
AdminLevelCollectionInterface $adminLevels = null,
84+
CountryInterface $country = null,
8585
$timezone = null
8686
) {
8787
$this->coordinates = $coordinates;
@@ -99,7 +99,7 @@ public function __construct(
9999
/**
100100
* Returns an array of coordinates (latitude, longitude).
101101
*
102-
* @return Coordinates
102+
* @return CoordinatesInterface
103103
*/
104104
public function getCoordinates()
105105
{
@@ -137,7 +137,7 @@ public function getLongitude()
137137
/**
138138
* Returns the bounds value.
139139
*
140-
* @return Bounds
140+
* @return BoundsInterface
141141
*/
142142
public function getBounds()
143143
{
@@ -198,7 +198,7 @@ public function getSubLocality()
198198
/**
199199
* Returns the administrative levels.
200200
*
201-
* @return AdminLevelCollection
201+
* @return AdminLevelCollectionInterface
202202
*/
203203
public function getAdminLevels()
204204
{
@@ -208,7 +208,7 @@ public function getAdminLevels()
208208
/**
209209
* Returns the country value.
210210
*
211-
* @return Country
211+
* @return CountryInterface
212212
*/
213213
public function getCountry()
214214
{

0 commit comments

Comments
 (0)