Skip to content

Commit

Permalink
Merge pull request #10 from seisigmasrl/feature/rnc-type
Browse files Browse the repository at this point in the history
Improving the rncType function by returning the Types enum.
  • Loading branch information
ricardov03 authored Feb 7, 2023
2 parents 49b2d50 + f43301a commit cdb5bd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/DgiiRncValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
}
}
5 changes: 3 additions & 2 deletions tests/DgiiRncValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Seisigma\DgiiRncValidator\DgiiRncValidator;
use Seisigma\DgiiRncValidator\helpers\Types;

test('check if the given string is a valid RNC', function () {
expect(DgiiRncValidator::validateRNC('123'))->toBeFalse()
Expand All @@ -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 () {
Expand Down

0 comments on commit cdb5bd5

Please sign in to comment.