b13/geocoding

Check for empty `$addressPart` can fail

Closed this issue · 1 comments

Is neither city nor zip is entered the check if (empty($addressPart)) fails because a white space makes $addressPart being not empty.

foreach ([$street, $zip . ' ' . $city, $country] as $addressPart) {
if (empty($addressPart)) {
continue;
}
$addressParts[] = trim($addressPart);
}
$address = ltrim(implode(',', $addressParts), ',');

Would be a solution to check with strlen(trim($addressPart)) <= 0 instead.

Background:
Otherwise this can lead to two consecutive commas. As a result the request leads sometimes to ZERO_RESULTS.

Is the solution okay? Shall I make a PR?

bmack commented

Yes. Please go ahead.