From a5a1656518f01b1eec5777fa94b607e8ed2762fc Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Sun, 12 Aug 2018 19:48:34 -0600 Subject: [PATCH] [add] New asserts --- api-payroll/src/application/EmployeeApplication.php | 5 +++++ api-payroll/src/service/Asserts.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 988be4f..1b5483a 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -145,7 +145,11 @@ class EmployeeApplication{ $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); $idEmployeeType = $requestData{'idEmployeeType'}; + $this->asserts->higherThanZero($idEmployeeType, 'idEmployeeType must be higher than zero.'); + $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 $securedFirstName = $this->cryptographyService->encryptString($firstName); @@ -421,6 +425,7 @@ class EmployeeApplication{ $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 $securedFirstName = $this->cryptographyService->encryptString($firstName); diff --git a/api-payroll/src/service/Asserts.php b/api-payroll/src/service/Asserts.php index 3976a26..d627334 100644 --- a/api-payroll/src/service/Asserts.php +++ b/api-payroll/src/service/Asserts.php @@ -69,5 +69,17 @@ class Asserts{ 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); + } + } } ?>