Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

III-2464 Return null when geocoder throws no result exception. #3

Merged
merged 5 commits into from
Jan 24, 2018

Conversation

LucWollants
Copy link

No description provided.

@@ -40,6 +39,12 @@ public function getCoordinates($address)
if ($encodedCacheData) {
$cacheData = json_decode($encodedCacheData, true);

// Some addresses have no coordinates, to cache these addresses 'NO_COORDINATES_FOUND' is used as value.
// When the 'NO_COORDINATES_FOUND' cached value is found null is returned as coordinate.
if ('NO_COORDINATES_FOUND' === $cacheData) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a constant for NO_COORDINATES_FOUND?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past I did overuse constants, now I use them not enough anymore. Bottomline, changed to constant.

);
// Some addresses have no coordinates, to cache these addresses 'NO_COORDINATES_FOUND' is used as value.
// When null is passed in as the coordinates, then 'NO_COORDINATES_FOUND' is stored as cache value.
$encodedCacheData = json_encode('NO_COORDINATES_FOUND');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be slightly better to first fill $cacheData with the value to cache (either NO_COORDINATES_FOUND or the array with lat and long), then afterwards perform the json_encode().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed beter to only call json_encode once.

{
public function __construct(
GeocoderInterface $geocoder,
LoggerInterface $logger

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could $logger be made optional, and use a NullLogger by default?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefered required logger in the constructor.

/**
* @test
*/
public function it_handles_null_coordinates_as_no_coordinates_found()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this test could be improved,. Maybe something in the vein of it_also_caches_when_no_coordinates_were_found() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed a much better name.

@LucWollants LucWollants merged commit 865d849 into master Jan 24, 2018
@LucWollants LucWollants deleted the feature/III-2464 branch January 24, 2018 21:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants