1 | <?php |
||
14 | class Coordinate implements ValueObjectInterface |
||
15 | { |
||
16 | /** @var Latitude */ |
||
17 | protected $latitude; |
||
18 | |||
19 | /** @var Longitude */ |
||
20 | protected $longitude; |
||
21 | |||
22 | /** @var Ellipsoid */ |
||
23 | protected $ellipsoid; |
||
24 | |||
25 | /** |
||
26 | * Returns a new Coordinate object from native PHP arguments |
||
27 | * |
||
28 | * @return self |
||
29 | * @throws \BadMethodCallException |
||
30 | */ |
||
31 | 2 | public static function fromNative() |
|
48 | |||
49 | /** |
||
50 | * Returns a new Coordinate object |
||
51 | * |
||
52 | * @param Latitude $latitude |
||
53 | * @param Longitude $longitude |
||
54 | * @param Ellipsoid $ellipsoid |
||
55 | */ |
||
56 | 9 | public function __construct(Latitude $latitude, Longitude $longitude, Ellipsoid $ellipsoid = null) |
|
66 | |||
67 | /** |
||
68 | * Tells whether tow Coordinate objects are equal |
||
69 | * |
||
70 | * @param ValueObjectInterface $coordinate |
||
71 | * @return bool |
||
72 | */ |
||
73 | 2 | public function sameValueAs(ValueObjectInterface $coordinate) |
|
84 | |||
85 | /** |
||
86 | * Returns latitude |
||
87 | * |
||
88 | * @return Latitude |
||
89 | */ |
||
90 | 7 | public function getLatitude() |
|
94 | |||
95 | /** |
||
96 | * Returns longitude |
||
97 | * |
||
98 | * @return Longitude |
||
99 | */ |
||
100 | 7 | public function getLongitude() |
|
104 | |||
105 | /** |
||
106 | * Returns ellipsoid |
||
107 | * |
||
108 | * @return Ellipsoid |
||
109 | */ |
||
110 | 7 | public function getEllipsoid() |
|
114 | |||
115 | /** |
||
116 | * Returns a degrees/minutes/seconds representation of the coordinate |
||
117 | * |
||
118 | * @return StringLiteral |
||
119 | */ |
||
120 | 1 | public function toDegreesMinutesSeconds() |
|
128 | |||
129 | /** |
||
130 | * Returns a decimal minutes representation of the coordinate |
||
131 | * |
||
132 | * @return StringLiteral |
||
133 | */ |
||
134 | 1 | public function toDecimalMinutes() |
|
142 | |||
143 | /** |
||
144 | * Returns a Universal Transverse Mercator projection representation of the coordinate in meters |
||
145 | * |
||
146 | * @return StringLiteral |
||
147 | */ |
||
148 | 1 | public function toUniversalTransverseMercator() |
|
156 | |||
157 | /** |
||
158 | * Calculates the distance between two Coordinate objects |
||
159 | * |
||
160 | * @param Coordinate $coordinate |
||
161 | * @param DistanceUnit $unit |
||
162 | * @param DistanceFormula $formula |
||
163 | * @return Real |
||
164 | */ |
||
165 | 1 | public function distanceFrom(Coordinate $coordinate, DistanceUnit $unit = null, DistanceFormula $formula = null) |
|
189 | |||
190 | /** |
||
191 | * Returns a native string version of the Coordiantes object in format "$latitude,$longitude" |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 1 | public function __toString() |
|
199 | |||
200 | /** |
||
201 | * Returns the underlying Coordinate object |
||
202 | * |
||
203 | * @param self $coordinate |
||
204 | * @return BaseCoordinate |
||
205 | */ |
||
206 | 4 | protected static function getBaseCoordinate(self $coordinate) |
|
215 | } |
||
216 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: