From f3de8d58a2442e723c1e9bba841f0d97383c89db Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Wed, 9 Dec 2020 13:41:18 +0100 Subject: [PATCH 1/6] Create index.php --- dist/index.php | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 dist/index.php diff --git a/dist/index.php b/dist/index.php new file mode 100644 index 0000000..6b064fd --- /dev/null +++ b/dist/index.php @@ -0,0 +1,123 @@ + $unicodeBase + ord($letter), + str_split( $countryCode) + ) + ); +} + +/** + * TODO: Finish implementation + * + * @param string $emoji + * + * @return string + * @internal + */ +function getUnicode(string $emoji): string +{ + return ''; +} From 72bdc9ebb53ca00a7d086133e81a212708d07549 Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Wed, 9 Dec 2020 13:51:06 +0100 Subject: [PATCH 2/6] Added autoloader entry --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index b84f735..2e33c12 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,10 @@ "issues": "https://github.com/annexare/Countries/issues" }, "require": {}, + "autoload": { + "files": [ + "dist/index.php" + ] + }, "homepage": "http://annexare.github.io/Countries/" } From acb5c91d0dffab6a139c8a8a16e675374ad7bc5d Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Sun, 3 Jan 2021 17:16:57 +0100 Subject: [PATCH 3/6] Removed Emoji functions due to PHP complexity issues --- dist/index.php | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/dist/index.php b/dist/index.php index 6b064fd..10c7e76 100644 --- a/dist/index.php +++ b/dist/index.php @@ -6,13 +6,8 @@ use JsonException; -use function array_map; use function file_get_contents; -use function idn_to_utf8; use function json_decode; -use function ord; -use function preg_match; -use function str_split; use const JSON_THROW_ON_ERROR; @@ -85,39 +80,3 @@ function languagesAll(): array { return load('languages.all.min.json'); } - -/** - * Returns country flag Emoji string. - * - * @param string $countryCode - * - * @return string - */ -function getEmojiFlag(string $countryCode): string -{ - $unicodeBase = 127462 - ord('A'); - $regex='/^[A-Z]{2}$/'; - - if (! preg_match($regex, $countryCode)) { - return ''; - } - - return idn_to_utf8(array_map( - fn(string $letter) => $unicodeBase + ord($letter), - str_split( $countryCode) - ) - ); -} - -/** - * TODO: Finish implementation - * - * @param string $emoji - * - * @return string - * @internal - */ -function getUnicode(string $emoji): string -{ - return ''; -} From c6c9180f9eac27086f615070e1a105991e48c10a Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Sun, 3 Jan 2021 17:17:06 +0100 Subject: [PATCH 4/6] Updated code style to match library --- dist/index.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dist/index.php b/dist/index.php index 10c7e76..5876ead 100644 --- a/dist/index.php +++ b/dist/index.php @@ -13,7 +13,7 @@ /** * Loads a JSON file relative to the current directory. - * + * * @param string $path * * @return array @@ -22,18 +22,18 @@ */ function load(string $path): array { - static $cache = []; + static $cache = []; - if (isset($cache[$path])) { - return $cache[$path]; - } + if (isset($cache[$path])) { + return $cache[$path]; + } - return $cache[$path] = json_decode( - file_get_contents(__DIR__ . '/' . $path), - true, - 512, - JSON_THROW_ON_ERROR - ); + return $cache[$path] = json_decode( + file_get_contents(__DIR__ . '/' . $path), + true, + 512, + JSON_THROW_ON_ERROR + ); } /** @@ -44,7 +44,7 @@ function load(string $path): array */ function continents(): array { - return load('continents.min.json'); + return load('continents.min.json'); } /** @@ -55,7 +55,7 @@ function continents(): array */ function countries(): array { - return load('countries.min.json'); + return load('countries.min.json'); } /** @@ -66,7 +66,7 @@ function countries(): array */ function languages(): array { - return load('languages.min.json'); + return load('languages.min.json'); } /** @@ -78,5 +78,5 @@ function languages(): array */ function languagesAll(): array { - return load('languages.all.min.json'); + return load('languages.all.min.json'); } From 145263a3d0022959e7e93f1ed73153faa6162882 Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Sun, 3 Jan 2021 17:17:34 +0100 Subject: [PATCH 5/6] Added PHPUnit --- .gitignore | 1 + composer.json | 5 ++++- phpunit.xml | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index 69a3efa..8180af9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.lock coverage +.phpunit.cache composer.phar diff --git a/composer.json b/composer.json index 2e33c12..f852aa2 100644 --- a/composer.json +++ b/composer.json @@ -37,5 +37,8 @@ "dist/index.php" ] }, - "homepage": "http://annexare.github.io/Countries/" + "homepage": "http://annexare.github.io/Countries/", + "require-dev": { + "phpunit/phpunit": "^9.5" + } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..cb2d0b0 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,25 @@ + + + + + tests + + + + + + dist + + + From 792f82862da3938beb577a987a3c08433284c763 Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Sun, 3 Jan 2021 17:17:50 +0100 Subject: [PATCH 6/6] Added basic test implementation --- tests/CountriesTest.php | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/CountriesTest.php diff --git a/tests/CountriesTest.php b/tests/CountriesTest.php new file mode 100644 index 0000000..f75399a --- /dev/null +++ b/tests/CountriesTest.php @@ -0,0 +1,76 @@ +