diff --git a/src/DgiiRncValidator.php b/src/DgiiRncValidator.php index e3c923c..4ad0c2b 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|string + public static function rncType(string $string): bool|Types { if (self::validateRNC($string)) { - return (strlen($string) === 9) ? Types::RNC->toString() : Types::CEDULA->toString(); + return (strlen($string) === 9) ? Types::RNC : Types::CEDULA; } return false; diff --git a/src/helpers/Types.php b/src/helpers/Types.php index 70b58c7..1aae322 100644 --- a/src/helpers/Types.php +++ b/src/helpers/Types.php @@ -18,4 +18,13 @@ public function toString(): string self::PASSPORT => 'PASSPORT', }; } + + public function toCode(): string + { + return match ($this) { + self::RNC => '01', + self::CEDULA => '02', + self::PASSPORT => '03', + }; + } } diff --git a/tests/DgiiRncValidatorTest.php b/tests/DgiiRncValidatorTest.php index 4747224..1121fd1 100644 --- a/tests/DgiiRncValidatorTest.php +++ b/tests/DgiiRncValidatorTest.php @@ -1,6 +1,7 @@ toBeFalse() @@ -10,8 +11,8 @@ }); test('check rncType return the type name', function () { - expect(DgiiRncValidator::rncType('123456789'))->toBe('RNC') - ->and(DgiiRncValidator::rncType('12345678901'))->toBe('CEDULA'); + expect(DgiiRncValidator::rncType('123456789'))->toBe(Types::RNC) + ->and(DgiiRncValidator::rncType('12345678901'))->toBe(Types::CEDULA); }); it('can return the details of an RNC if true', function () {