[add] New asserts

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-12 19:48:34 -06:00
parent 19d1f57240
commit a5a1656518
2 changed files with 17 additions and 0 deletions

View File

@ -145,7 +145,11 @@ class EmployeeApplication{
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
$idEmployeeType = $requestData{'idEmployeeType'}; $idEmployeeType = $requestData{'idEmployeeType'};
$this->asserts->higherThanZero($idEmployeeType, 'idEmployeeType must be higher than zero.');
$contractType = $requestData{'contractType'}; $contractType = $requestData{'contractType'};
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
$this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.');
// Encrypting the sensitive data // Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName); $securedFirstName = $this->cryptographyService->encryptString($firstName);
@ -421,6 +425,7 @@ class EmployeeApplication{
$contractType = $requestData{'contractType'}; $contractType = $requestData{'contractType'};
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); $this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
$this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.');
// Encrypting the sensitive data // Encrypting the sensitive data
$securedFirstName = $this->cryptographyService->encryptString($firstName); $securedFirstName = $this->cryptographyService->encryptString($firstName);

View File

@ -69,5 +69,17 @@ class Asserts{
throw new Exception($errorMessage); throw new Exception($errorMessage);
} }
} }
/**
* @param $string string
* @param $array array
* @param $errorMessage string
* @throws Exception
*/
function existInArray($string, $array, $errorMessage){
if(!in_array($string, $array)){
throw new Exception($errorMessage);
}
}
} }
?> ?>