Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for foreigners #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Support/BaseIdentification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class BaseIdentification implements IdentificationContract
* @var int
*/
protected $provinces = 24;

/**
* Province code for foreigners
* @var int
*/
protected $foreignersCode = 30;

/**
* Length of the different types of identification
Expand Down Expand Up @@ -64,6 +70,7 @@ public function validate(string $identification_number)
$this->provinceCodeValidation($identification_number);
$this->thirdDigitValidation($identification_number);
$this->lastsDigitsValidation($identification_number);
$this->foreignersValidation($identification_number);

if ($this instanceof PublicRuc || $this instanceof PrivateRuc) {
$this->moduleElevenValidation($identification_number);
Expand Down Expand Up @@ -111,6 +118,23 @@ protected function provinceCodeValidation(string $identification_number): void
throw new Exception("In your province code must be between 01 and {$this->provinces}.");
}
}

/**
* Validate the province code (first two numbers of CI/RUC)
* The first 2 positions correspond to the province where it was issued,
* so the first two numbers will not be greater than 24 or less than 1
*
* @param string $identification_number Identification document
* @throws Exception
*/
protected function foreignersValidation(string $identification_number): void
{
$code = $this->getProvinceCodeValue($identification_number);

if ($code !== 30) {
throw new Exception("The province code for foreigners can only be 30");
}
}

/**
* Valid the third digit
Expand Down