Skip to content

Commit ba6a2d7

Browse files
authored
Merge pull request #40 from programmatordev/1.x
1.x
2 parents 38b3137 + c180983 commit ba6a2d7

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"php-http/client-common": "^2.7",
1818
"php-http/discovery": "^1.18",
1919
"php-http/logger-plugin": "^1.3",
20-
"programmatordev/yet-another-php-validator": "^0.1.1",
20+
"programmatordev/yet-another-php-validator": "^0.2",
2121
"psr/cache": "^2.0 || ^3.0",
2222
"psr/http-client": "^1.0",
2323
"psr/http-factory": "^1.0",

src/Config.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class Config
1717

1818
public function __construct(array $options = [])
1919
{
20-
$resolver = new OptionsResolver();
21-
$this->configureOptions($resolver);
22-
$this->options = $resolver->resolve($options);
20+
$this->options = $this->resolveOptions($options);
2321
}
2422

25-
private function configureOptions(OptionsResolver $resolver): void
23+
private function resolveOptions(array $options): array
2624
{
25+
$resolver = new OptionsResolver();
26+
2727
$resolver->setDefaults([
2828
'unitSystem' => UnitSystem::METRIC,
2929
'language' => Language::ENGLISH,
@@ -46,6 +46,8 @@ private function configureOptions(OptionsResolver $resolver): void
4646
});
4747
$resolver->setAllowedValues('unitSystem', UnitSystem::getList());
4848
$resolver->setAllowedValues('language', Language::getList());
49+
50+
return $resolver->resolve($options);
4951
}
5052

5153
public function getApplicationKey(): string

src/Endpoint/AbstractEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function buildUrl(UriInterface|string $baseUrl, array $query): string
133133

134134
// Add application key to all requests
135135
$query = $query + [
136-
'appid' => $this->api->getConfig()->getApplicationKey()
136+
'appid' => $this->config->getApplicationKey()
137137
];
138138

139139
return \sprintf('%s?%s', $baseUrl, http_build_query($query));

src/Endpoint/GeocodingEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
6767
public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocation
6868
{
6969
Validator::notBlank()->assert($zipCode, 'zipCode');
70-
Validator::notBlank()->assert($countryCode, 'countryCode');
70+
Validator::country()->assert($countryCode, 'countryCode');
7171

7272
$data = $this->sendRequest(
7373
method: 'GET',

tests/GeocodingEndpointTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ public function testGeocodingGetByZipCode()
5454
$this->assertSame(-9.1333, $coordinate->getLongitude());
5555
}
5656

57-
#[DataProvider('provideGeocodingGetByZipCodeWithBlankValueData')]
58-
public function testGeocodingGetByZipCodeWithBlankValue(string $zipCode, string $countryCode)
57+
#[DataProvider('provideGeocodingGetByZipCodeWithInvalidValueData')]
58+
public function testGeocodingGetByZipCodeWithInvalidValue(string $zipCode, string $countryCode)
5959
{
6060
$this->expectException(ValidationException::class);
6161
$this->getApi()->getGeocoding()->getByZipCode($zipCode, $countryCode);
6262
}
6363

64-
public static function provideGeocodingGetByZipCodeWithBlankValueData(): \Generator
64+
public static function provideGeocodingGetByZipCodeWithInvalidValueData(): \Generator
6565
{
6666
yield 'blank zip code' => ['', 'pt'];
6767
yield 'blank country code' => ['1000-100', ''];
68+
yield 'invalid country code' => ['1000-100', 'invalid'];
6869
}
6970

7071
public function testGeocodingGetByCoordinate()

0 commit comments

Comments
 (0)