Skip to content

Commit

Permalink
added missing PHP 7.4 type hints
Browse files Browse the repository at this point in the history
- PHP 7.4 hints
- docBlock changes
- validation for italy
  • Loading branch information
Stefan Kientzler committed Sep 21, 2020
1 parent ad9af88 commit 81d0105
Show file tree
Hide file tree
Showing 29 changed files with 432 additions and 342 deletions.
22 changes: 11 additions & 11 deletions SKien/Sepa/CntryValidation/SepaCntryValidation.php
Expand Up @@ -6,13 +6,13 @@
* Classes to define the country specific validation of IBAN, BIC and
* CI must implement this interfaace.
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -22,26 +22,26 @@ interface SepaCntryValidation
* create instance of validation.
* @param string $strCntry 2 sign country code (ISO 3166-1)
*/
public function __construct($strCntry);
public function __construct(string $strCntry);

/**
* validates given IBAN.
* @param string $strIBAN
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
*/
public function validateIBAN($strIBAN);
public function validateIBAN(string $strIBAN) : int;

/**
* validates given BIC.
* @param string $strBIC
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
*/
public function validateBIC($strBIC);
public function validateBIC(string $strBIC) : int;

/**
* validates given CI (Creditor Scheme Identification).
* @param string $strCI
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
*/
public function validateCI($strCI);
public function validateCI(string $strCI) : int;
}
10 changes: 5 additions & 5 deletions SKien/Sepa/CntryValidation/SepaCntryValidationAT.php
Expand Up @@ -30,13 +30,13 @@
*
* *** All validation can be done with specification of length and regex to match format! ***
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -46,7 +46,7 @@ class SepaCntryValidationAT extends SepaCntryValidationBase
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
$this->strCntry = 'AT';
$this->iLenIBAN = 20;
Expand Down
14 changes: 7 additions & 7 deletions SKien/Sepa/CntryValidation/SepaCntryValidationBE.php
Expand Up @@ -23,13 +23,13 @@
* ### CI format
* See method SepaCntryValidationBE::validateCI()
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -39,7 +39,7 @@ class SepaCntryValidationBE extends SepaCntryValidationBase
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
$this->strCntry = 'BE';
$this->iLenIBAN = 16;
Expand Down Expand Up @@ -76,9 +76,9 @@ public function __construct($strCntry)
* Length: 20
*
* @param string $strCI
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
*/
public function validateCI($strCI)
public function validateCI(string $strCI) : int
{
// toupper, trim and remove containing blanks
$strCheck = str_replace(' ', '', trim(strtoupper($strCI)));
Expand Down
64 changes: 34 additions & 30 deletions SKien/Sepa/CntryValidation/SepaCntryValidationBase.php
Expand Up @@ -22,40 +22,40 @@
* order to map this rule.
* @see SepaCntryValidationBE class
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
class SepaCntryValidationBase implements SepaCntryValidation
{
/** @var string 2 digit ISO country code (ISO 3166-1) */
protected $strCntry = '';
protected string $strCntry = '';
/** @var int length of the IBAN */
protected $iLenIBAN = -1;
protected int $iLenIBAN = -1;
/** @var string regular expression to validate the format of the IBAN */
protected $strRegExIBAN = '';
protected string $strRegExIBAN = '';
/** @var bool if true, alphanum values in the IBAN allowed */
protected $bAlphaNumIBAN = false;
protected bool $bAlphaNumIBAN = false;
/** @var int length of the IC */
protected $iLenCI = -1;
protected int $iLenCI = -1;
/** @var string regular expression to validate the format of the CI */
protected $strRegExCI = '';
protected string $strRegExCI = '';
/** @var bool if true, alphanum values in the CI allowed */
protected $bAlphaNumCI = false;
protected bool $bAlphaNumCI = false;
/** @var string last calculated checksum */
protected $strLastCheckSum = '';
protected string $strLastCheckSum = '';

/**
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
if (strtoupper($strCntry) != $this->strCntry) {
trigger_error('instanciation with invalid country ' . $strCntry . ' (expected ' . $this->strCntry . ')', E_USER_ERROR);
Expand All @@ -69,13 +69,13 @@ public function __construct($strCntry)
* @link http://www.pruefziffernberechnung.de/I/IBAN.shtml
*
* @param string $strIBAN
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
* Sepa::ERR_IBAN_INVALID_CNTRY invalid country code
* Sepa::ERR_IBAN_INVALID_LENGTH invalid length
* Sepa::ERR_IBAN_INVALID_SIGN IBAN contains invalid sign(s)
* Sepa::ERR_IBAN_CHECKSUM wrong checksum
*/
public function validateIBAN($strIBAN)
public function validateIBAN(string $strIBAN) : int
{
// toupper, trim and remove containing blanks
$strIBAN = str_replace(' ', '', trim(strtoupper($strIBAN)));
Expand Down Expand Up @@ -108,9 +108,9 @@ public function validateIBAN($strIBAN)
* as far as I have determined, the format of the BIC is uniform within
* the participating countries.
* @param string $strBIC
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
*/
public function validateBIC($strBIC)
public function validateBIC(string $strBIC) : int
{
if (substr($strBIC, 4, 2) != $this->strCntry) {
return Sepa::ERR_BIC_INVALID_CNTRY;
Expand Down Expand Up @@ -138,14 +138,17 @@ public function validateBIC($strBIC)
* @link https://www.europeanpaymentscouncil.eu/sites/default/files/kb/file/2019-09/EPC262-08%20v7.0%20Creditor%20Identifier%20Overview_0.pdf
* @link https://www.europeanpaymentscouncil.eu/sites/default/files/KB/files/EPC114-06%20SDD%20Core%20Interbank%20IG%20V9.0%20Approved.pdf#page=10
*
* online CI Validator
* @link http://www.maric.info/fin/SEPA/ddchkden.htm
*
* @param string $strCI
* @return number OK ( 0 ) or errorcode
* @return int OK ( 0 ) or errorcode
* Sepa::ERR_CI_INVALID_CNTRY invalid country code.
* Sepa::ERR_CI_INVALID_LENGTH invalid length.
* Sepa::ERR_CI_INVALID_SIGN CI contains invalid sign(s).
* Sepa::ERR_CI_CHECKSUM wrong checksum.
*/
public function validateCI($strCI)
public function validateCI(string $strCI) : int
{
// toupper, trim and remove containing blanks
$strCheck = str_replace(' ', '', trim(strtoupper($strCI)));
Expand Down Expand Up @@ -175,7 +178,7 @@ public function validateCI($strCI)
* Return last calculated checksum.
* @return string
*/
public function getLastCheckSum()
public function getLastCheckSum() : string
{
return $this->strLastCheckSum;
}
Expand All @@ -186,11 +189,11 @@ public function getLastCheckSum()
* @param string $strCheck
* @return string
*/
protected function getCheckSum($strCheck)
protected function getCheckSum(string $strCheck) : string
{
// calculate checksum
// 1. move 6 digit feft and add numerical countrycode
$strCS1 = $this->adjustFP(bcadd(bcmul($strCheck, '1000000'), intval($this->getAlpha2CntryCode()) * 100));
$strCS1 = $this->adjustFP(bcadd(bcmul($strCheck, '1000000'), $this->getAlpha2CntryCode() * 100));
// 2. modulo 97 value
$strCS2 = $this->adjustFP(bcmod($strCS1, '97'));
// 3. subtract value from 98
Expand All @@ -210,7 +213,7 @@ protected function getCheckSum($strCheck)
* @param string $str
* @return string
*/
protected function adjustFP( $str )
protected function adjustFP(string $str) : string
{
if( strpos( '.', $str ) !== false ) {
$str = substr($str, 0, strpos('.', $str));
Expand All @@ -222,23 +225,24 @@ protected function adjustFP( $str )
* Get the ALPHA-2 country code.
* To calc the checksum, the first four digits of the IBAN (country code and check digit)
* have to be placed at the end of the IBAN. Check digit is represented by 00 for calculation.
* @return string
*/
protected function getAlpha2CntryCode()
protected function getAlpha2CntryCode() : string
{
$strNumCode = $this->convCharToNum($this->strCntry[0]) . $this->convCharToNum($this->strCntry[1]);
return $strNumCode;
}

/**
* replace all alpha chars with the numeric substitution
* @param unknown $strCheck
* @return mixed
* @param string $strCheck
* @return string
*/
protected function replaceAlpha($strCheck)
protected function replaceAlpha(string $strCheck) : string
{
// account number may contains characters
foreach (range('A', 'Z') as $ch){
$strCheck = str_replace($ch, $this->convCharToNum($ch), $strCheck);
$strCheck = str_replace((string)$ch, $this->convCharToNum((string)$ch), $strCheck);
}
return $strCheck;
}
Expand All @@ -252,10 +256,10 @@ protected function replaceAlpha($strCheck)
* D = 13 I = 18 N = 23 S = 28 X = 33
* E = 14 J = 19 O = 24 T = 29 Y = 34
*
* @param unknown $ch
* @param string $ch
* @return string
*/
protected function convCharToNum($ch)
protected function convCharToNum(string $ch) : string
{
$iValue = ord($ch) - ord('A') + 10;
return strval($iValue);
Expand Down
10 changes: 5 additions & 5 deletions SKien/Sepa/CntryValidation/SepaCntryValidationCH.php
Expand Up @@ -29,13 +29,13 @@
*
* *** All validation can be done with specification of length and regex to match format! ***
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -45,7 +45,7 @@ class SepaCntryValidationCH extends SepaCntryValidationBase
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
$this->strCntry = 'CH';
$this->iLenIBAN = 21;
Expand Down
10 changes: 5 additions & 5 deletions SKien/Sepa/CntryValidation/SepaCntryValidationDE.php
Expand Up @@ -30,13 +30,13 @@
*
* *** All validation can be done with specification of length and regex to match format! ***
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -46,7 +46,7 @@ class SepaCntryValidationDE extends SepaCntryValidationBase
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
$this->strCntry = 'DE';
$this->iLenIBAN = 22;
Expand Down
10 changes: 5 additions & 5 deletions SKien/Sepa/CntryValidation/SepaCntryValidationEE.php
Expand Up @@ -32,13 +32,13 @@
*
* *** All validation can be done with specification of length and regex to match format! ***
*
* ### History
* ** 2020-05-21 **
* - initial version
* #### History:
* - *2020-05-21* initial version.
* - *2020-07-22* added missing PHP 7.4 type hints / docBlock changes
*
* @package SKien/Sepa
* @since 1.1.0
* @version 1.1.0
* @version 1.2.0
* @author Stefanius <s.kien@online.de>
* @copyright MIT License - see the LICENSE file for details
*/
Expand All @@ -48,7 +48,7 @@ class SepaCntryValidationEE extends SepaCntryValidationBase
* create instance of validation.
* @param string $strCntry 2 sign country code
*/
public function __construct($strCntry)
public function __construct(string $strCntry)
{
$this->strCntry = 'EE';
$this->iLenIBAN = 20;
Expand Down

0 comments on commit 81d0105

Please sign in to comment.