From 07b5f45ec1493f2ae1ac5223fb47810f0910dd0a Mon Sep 17 00:00:00 2001 From: jmuto Date: Tue, 2 Nov 2021 15:12:59 -0400 Subject: [PATCH 1/3] DS-3439 extend country mapping methods to get approved country list and bool method to assess if approved --- src/CountryMapping.php | 17 ++++++++++++++++- tests/ApprovedCountryTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/ApprovedCountryTest.php diff --git a/src/CountryMapping.php b/src/CountryMapping.php index aeda8e7..1daa327 100644 --- a/src/CountryMapping.php +++ b/src/CountryMapping.php @@ -11,7 +11,7 @@ class CountryMapping private $imageFlagBasePath = 'https://storage.googleapis.com/language_mapping/flags'; private $imageCountryBasePath = 'https://storage.googleapis.com/country_mapper/flags'; - public function getMapping() + public function getMapping(): array { return [ [ @@ -86,4 +86,19 @@ public function getMapping() ], ]; } + + public function getApprovedCountryList(): array + { + return array_map( + function ($row) { + return $row['short_code']; + }, + (new CountryMapping())->getMapping() + ); + } + + public function isApprovedCountry(string $country): bool + { + return in_array($country, $this->getApprovedCountryList()); + } } diff --git a/tests/ApprovedCountryTest.php b/tests/ApprovedCountryTest.php new file mode 100644 index 0000000..dd65c11 --- /dev/null +++ b/tests/ApprovedCountryTest.php @@ -0,0 +1,26 @@ +getApprovedCountryList(); + $this->assertSame($approvedList, $countries); + } + + public function testApprovedCountryReturnsFalse() + { + $this->assertFalse((new CountryMapping())->isApprovedCountry('AL')); + } + + public function testApprovedCountryReturnsTrue() + { + $this->assertTrue((new CountryMapping())->isApprovedCountry('RU')); + } +} From 9a93b21cafdec7c63d5c7fc57d38dfe2e9e76860 Mon Sep 17 00:00:00 2001 From: jmuto Date: Tue, 2 Nov 2021 15:15:31 -0400 Subject: [PATCH 2/3] DS-3439 minor --- src/CountryMapping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CountryMapping.php b/src/CountryMapping.php index 1daa327..1ba0f5d 100644 --- a/src/CountryMapping.php +++ b/src/CountryMapping.php @@ -93,7 +93,7 @@ public function getApprovedCountryList(): array function ($row) { return $row['short_code']; }, - (new CountryMapping())->getMapping() + $this->getMapping() ); } From eb9c66fc23a58496275930e65dfe0bd51ee49e2f Mon Sep 17 00:00:00 2001 From: jmuto Date: Tue, 2 Nov 2021 15:15:53 -0400 Subject: [PATCH 3/3] DS-3439 minor --- src/CountryMapping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CountryMapping.php b/src/CountryMapping.php index 1ba0f5d..ba742a7 100644 --- a/src/CountryMapping.php +++ b/src/CountryMapping.php @@ -5,7 +5,7 @@ class CountryMapping { /** - * Using assests flags from our language mapper + * Using assets flags from our language mapper * @var string */ private $imageFlagBasePath = 'https://storage.googleapis.com/language_mapping/flags';