Skip to content

Commit dc8a1bd

Browse files
committed
Return confidence from OpenCage API
1 parent ce6ee28 commit dc8a1bd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/Provider/OpenCage/Model/OpenCageAddress.php

+21
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ final class OpenCageAddress extends Address
4949
*/
5050
private $formattedAddress;
5151

52+
/**
53+
* @var int|null
54+
*/
55+
private $confidence;
56+
5257
public function withMGRS(?string $mgrs = null): self
5358
{
5459
$new = clone $this;
@@ -128,4 +133,20 @@ public function getFormattedAddress()
128133
{
129134
return $this->formattedAddress;
130135
}
136+
137+
public function withConfidence(?int $confidence = null): self
138+
{
139+
$new = clone $this;
140+
$new->confidence = $confidence;
141+
142+
return $new;
143+
}
144+
145+
/**
146+
* @return int|null
147+
*/
148+
public function getConfidence()
149+
{
150+
return $this->confidence;
151+
}
131152
}

src/Provider/OpenCage/OpenCage.php

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private function executeQuery(string $url, ?string $locale = null): AddressColle
154154
$address = $address->withGeohash(isset($annotations['geohash']) ? $annotations['geohash'] : null);
155155
$address = $address->withWhat3words(isset($annotations['what3words'], $annotations['what3words']['words']) ? $annotations['what3words']['words'] : null);
156156
$address = $address->withFormattedAddress($location['formatted']);
157+
$address = $address->withConfidence($location['confidence']);
157158

158159
$results[] = $address;
159160
}

src/Provider/OpenCage/Tests/OpenCageTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testGeocodeWithRealAddress(): void
8383
$this->assertEquals('u09tyr78tz64jdcgfnhe', $result->getGeohash());
8484
$this->assertEquals('listed.emphasis.greeting', $result->getWhat3words());
8585
$this->assertEquals('10 Avenue Gambetta, 75020 Paris, France', $result->getFormattedAddress());
86+
$this->assertEquals(10, $result->getConfidence());
8687
}
8788

8889
public function testReverseWithRealCoordinates(): void

0 commit comments

Comments
 (0)