From d22d67ba88b5f95cd359d4a2a5e5a491cdc9d9b9 Mon Sep 17 00:00:00 2001 From: Sebastian Gehrt Date: Sun, 11 Jun 2023 10:32:05 +0200 Subject: [PATCH 1/2] Add ISO 3166 Alpha 2 Validation --- src/IsoCodes/ISO3166A2.php | 275 +++++++++++++++++++++++++ tests/IsoCodes/Tests/ISO3166A2Test.php | 35 ++++ 2 files changed, 310 insertions(+) create mode 100644 src/IsoCodes/ISO3166A2.php create mode 100644 tests/IsoCodes/Tests/ISO3166A2Test.php diff --git a/src/IsoCodes/ISO3166A2.php b/src/IsoCodes/ISO3166A2.php new file mode 100644 index 0000000..f0a4b03 --- /dev/null +++ b/src/IsoCodes/ISO3166A2.php @@ -0,0 +1,275 @@ + Date: Sun, 11 Jun 2023 10:53:57 +0200 Subject: [PATCH 2/2] Fix validation --- src/IsoCodes/ISO3166A2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IsoCodes/ISO3166A2.php b/src/IsoCodes/ISO3166A2.php index f0a4b03..2a9fb05 100644 --- a/src/IsoCodes/ISO3166A2.php +++ b/src/IsoCodes/ISO3166A2.php @@ -7,7 +7,7 @@ */ class ISO3166A2 implements IsoCodeInterface { - protected $countries = ['AD', + private CONST COUNTRIES = ['AD', 'AE', 'AF', 'AG', @@ -270,6 +270,6 @@ public static function validate($alpha2) if($alpha2 === null){ return false; } - return in_array($alpha2); + return in_array($alpha2, self::COUNTRIES, true ); } } \ No newline at end of file