Skip to content

Commit

Permalink
fix: Ensure geocoding address and the need for geocoding is correctly…
Browse files Browse the repository at this point in the history
… determined
  • Loading branch information
tweis committed Oct 23, 2024
1 parent f53bd75 commit 125e2c2
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Classes/Service/GeoCoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,36 @@ public function __construct(

public function getGeoCodingAddress(array $tcaRecord): string
{
return $tcaRecord[$this->fieldMap->addressToGeocode] ?? $tcaRecord[$this->fieldMap->addressToDisplay] ?? '';
if (
array_key_exists($this->fieldMap->addressToGeocode, $tcaRecord) &&
$tcaRecord[$this->fieldMap->addressToGeocode] !== ''
) {
return $tcaRecord[$this->fieldMap->addressToGeocode];
}

if (
array_key_exists($this->fieldMap->addressToDisplay, $tcaRecord) &&
$tcaRecord[$this->fieldMap->addressToDisplay] !== ''
) {
return $tcaRecord[$this->fieldMap->addressToDisplay];
}

return '';
}

public function needsToBeGeoCoded(array $tcaRecord): bool
{
return (!($tcaRecord[$this->fieldMap->latitude] ?? false) && !($tcaRecord[$this->fieldMap->longitude] ?? false))
|| (($tcaRecord[$this->fieldMap->probability] ?? PHP_INT_MAX) > $this->probabilityThreshold);
$hasLatitude = array_key_exists($this->fieldMap->latitude, $tcaRecord)
&& $tcaRecord[$this->fieldMap->latitude] !== '';

$hasLongitude = array_key_exists($this->fieldMap->longitude, $tcaRecord)
&& $tcaRecord[$this->fieldMap->longitude] !== '';

$probability = array_key_exists($this->fieldMap->probability, $tcaRecord)
? ($tcaRecord[$this->fieldMap->probability] ?: 0)
: 0;

return (!$hasLatitude && !$hasLongitude) || ($probability > $this->probabilityThreshold);
}

public function setProbabilityToManually(array $tcaRecord): array
Expand Down

0 comments on commit 125e2c2

Please sign in to comment.