From d2af5ab372543c5d665fb3d4138d26761a9c6cd4 Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:12:14 -0400 Subject: [PATCH 1/7] Fixing (Again) PHP support on the composer.json file. Minimum v.8.1. - Upgrading dependencies. --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0ff5c3b..4a62a86 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,13 @@ } ], "require": { - "php": "8.*", + "php": ">=8.1", "ext-soap": "*" }, "require-dev": { - "pestphp/pest": "^1.20", - "laravel/pint": "^1.2", - "spatie/ray": "^1.28" + "pestphp/pest": "^1.22.4", + "laravel/pint": "^1.4.1", + "spatie/ray": "^1.36" }, "autoload": { "psr-4": { From 809a8e1b914298756680166cd7179d10bcd27591 Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:12:59 -0400 Subject: [PATCH 2/7] Adding the Types enum. Replacing self name with the Self keyword. --- src/Helpers/Status.php | 4 ++-- src/Helpers/Types.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/Helpers/Types.php diff --git a/src/Helpers/Status.php b/src/Helpers/Status.php index b89c0b5..da91296 100644 --- a/src/Helpers/Status.php +++ b/src/Helpers/Status.php @@ -10,8 +10,8 @@ enum Status: int public function toString(): string { return match ($this) { - Status::ACTIVE => 'Active', - Status::INACTIVE => 'Inactive' + self::ACTIVE => 'Active', + self::INACTIVE => 'Inactive' }; } } diff --git a/src/Helpers/Types.php b/src/Helpers/Types.php new file mode 100644 index 0000000..3be5df1 --- /dev/null +++ b/src/Helpers/Types.php @@ -0,0 +1,19 @@ + 'RNC', + self::CEDULA => 'Cédula', + self::PASSPORT => 'Pasaporte', + }; + } +} From f0b67d18f5173b3e99b22216806ff6778106c6ab Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:14:04 -0400 Subject: [PATCH 3/7] Adding the rncType method to validate RNC type. --- src/DgiiRncValidator.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/DgiiRncValidator.php b/src/DgiiRncValidator.php index 01977c6..73ee33f 100755 --- a/src/DgiiRncValidator.php +++ b/src/DgiiRncValidator.php @@ -5,6 +5,7 @@ namespace Seisigma\DgiiRncValidator; use Seisigma\DgiiRncValidator\Helpers\Status; +use Seisigma\DgiiRncValidator\Helpers\Types; use Seisigma\DgiiRncValidator\Helpers\Utils; use SoapClient; @@ -20,6 +21,15 @@ public static function validateRNC(string $string): bool return (bool) count($matches); } + public static function rncType(string $string): bool | Types + { + if (self::validateRNC($string)) { + return (strlen($string) === 9) ? Types::RNC : Types::CEDULA; + } + + return false; + } + /** * @throws \Exception */ From 91846f61dbcef172f8ed3d6fa07454b122607836 Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:17:43 -0400 Subject: [PATCH 4/7] Updating the documentation. --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bef3a61..8e5d934 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,25 @@ $validatedRnc = DgiiRncValidator::validateRNC("132620951"); var_dump($validatedRnc); // bool(true) // 123456789 is an invalid RNC -$validatedRnc = DgiiRncValidator::check("123456789"); +$validatedRnc = DgiiRncValidator::validateRNC("123456789"); var_dump($validatedRnc); // bool(false) ``` +### rncType +Validate if a given string is a valid RNC.
+__How to use it:__ +```php +require Seisigma\DgiiRncValidator\DgiiRncValidator; +... +// 132620951 is a valid RNC +$rncType = DgiiRncValidator::rncType("132620951"); +var_dump($rncType); // string(RNC) + +// 123456789 is an invalid RNC +$rncType = DgiiRncValidator::rncType("04800009577"); +var_dump($rncType); // string(Cédula) +``` + ## Helper Functions Just in case you need a few extra tools, here's a list of utility functions: From ab458f7fa94568a443587a8240ac7e7541e38ffe Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:31:39 -0400 Subject: [PATCH 5/7] Fixing return type. --- src/DgiiRncValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DgiiRncValidator.php b/src/DgiiRncValidator.php index 73ee33f..4e75bb1 100755 --- a/src/DgiiRncValidator.php +++ b/src/DgiiRncValidator.php @@ -21,10 +21,10 @@ public static function validateRNC(string $string): bool return (bool) count($matches); } - public static function rncType(string $string): bool | Types + public static function rncType(string $string): bool | string { if (self::validateRNC($string)) { - return (strlen($string) === 9) ? Types::RNC : Types::CEDULA; + return (strlen($string) === 9) ? Types::RNC->toString() : Types::CEDULA->toString(); } return false; From 9f26750e3d9ee6024981421daff522a5b31b7b7c Mon Sep 17 00:00:00 2001 From: Ricardo Vargas Date: Tue, 7 Feb 2023 06:31:52 -0400 Subject: [PATCH 6/7] Adding test function to the package. --- tests/DgiiRncValidatorTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/DgiiRncValidatorTest.php b/tests/DgiiRncValidatorTest.php index 07f8d68..e3418a1 100644 --- a/tests/DgiiRncValidatorTest.php +++ b/tests/DgiiRncValidatorTest.php @@ -9,6 +9,11 @@ ->and(DgiiRncValidator::validateRNC('12345678901'))->toBeTrue(); }); +test('check rncType return the type name', function (){ + expect(DgiiRncValidator::rncType('123456789'))->toBe('RNC') + ->and(DgiiRncValidator::rncType('12345678901'))->toBe('Cédula'); +}); + it('can return the details of an RNC if true', function () { $id = '132620951'; expect(DgiiRncValidator::check($id)) From 4ca7e60f67d5eef12cf696f253611d0ba29a99da Mon Sep 17 00:00:00 2001 From: ricardov03 Date: Tue, 7 Feb 2023 11:14:06 +0000 Subject: [PATCH 7/7] Fix styling --- src/DgiiRncValidator.php | 4 ++-- tests/DgiiRncValidatorTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DgiiRncValidator.php b/src/DgiiRncValidator.php index 4e75bb1..cdd8f9a 100755 --- a/src/DgiiRncValidator.php +++ b/src/DgiiRncValidator.php @@ -21,7 +21,7 @@ public static function validateRNC(string $string): bool return (bool) count($matches); } - public static function rncType(string $string): bool | string + public static function rncType(string $string): bool|string { if (self::validateRNC($string)) { return (strlen($string) === 9) ? Types::RNC->toString() : Types::CEDULA->toString(); @@ -65,7 +65,7 @@ public static function check(string $id): array|bool 'rnc' => $id, 'name' => $name, 'commercial_name' => $commercialName, - 'status' => Status::from((int)$status)->toString(), + 'status' => Status::from((int) $status)->toString(), ]; } } diff --git a/tests/DgiiRncValidatorTest.php b/tests/DgiiRncValidatorTest.php index e3418a1..ca49de3 100644 --- a/tests/DgiiRncValidatorTest.php +++ b/tests/DgiiRncValidatorTest.php @@ -9,7 +9,7 @@ ->and(DgiiRncValidator::validateRNC('12345678901'))->toBeTrue(); }); -test('check rncType return the type name', function (){ +test('check rncType return the type name', function () { expect(DgiiRncValidator::rncType('123456789'))->toBe('RNC') ->and(DgiiRncValidator::rncType('12345678901'))->toBe('Cédula'); });