diff --git a/src/Provider/OpenCage/Model/OpenCageAddress.php b/src/Provider/OpenCage/Model/OpenCageAddress.php index 8c275ed2f..8ccad5145 100644 --- a/src/Provider/OpenCage/Model/OpenCageAddress.php +++ b/src/Provider/OpenCage/Model/OpenCageAddress.php @@ -49,6 +49,11 @@ final class OpenCageAddress extends Address */ private $formattedAddress; + /** + * @var int|null + */ + private $confidence; + public function withMGRS(?string $mgrs = null): self { $new = clone $this; @@ -128,4 +133,20 @@ public function getFormattedAddress() { return $this->formattedAddress; } + + public function withConfidence(?int $confidence = null): self + { + $new = clone $this; + $new->confidence = $confidence; + + return $new; + } + + /** + * @return int|null + */ + public function getConfidence() + { + return $this->confidence; + } } diff --git a/src/Provider/OpenCage/OpenCage.php b/src/Provider/OpenCage/OpenCage.php index e91b1c251..ddb665b0a 100644 --- a/src/Provider/OpenCage/OpenCage.php +++ b/src/Provider/OpenCage/OpenCage.php @@ -154,6 +154,7 @@ private function executeQuery(string $url, ?string $locale = null): AddressColle $address = $address->withGeohash(isset($annotations['geohash']) ? $annotations['geohash'] : null); $address = $address->withWhat3words(isset($annotations['what3words'], $annotations['what3words']['words']) ? $annotations['what3words']['words'] : null); $address = $address->withFormattedAddress($location['formatted']); + $address = $address->withConfidence($location['confidence']); $results[] = $address; } diff --git a/src/Provider/OpenCage/Tests/OpenCageTest.php b/src/Provider/OpenCage/Tests/OpenCageTest.php index 3a9a63449..acd91e2ac 100644 --- a/src/Provider/OpenCage/Tests/OpenCageTest.php +++ b/src/Provider/OpenCage/Tests/OpenCageTest.php @@ -83,6 +83,7 @@ public function testGeocodeWithRealAddress(): void $this->assertEquals('u09tyr78tz64jdcgfnhe', $result->getGeohash()); $this->assertEquals('listed.emphasis.greeting', $result->getWhat3words()); $this->assertEquals('10 Avenue Gambetta, 75020 Paris, France', $result->getFormattedAddress()); + $this->assertEquals(10, $result->getConfidence()); } public function testReverseWithRealCoordinates(): void