cvs: pear /Validate/Validate Finance.php /Validate/Validate/Finance CreditCard.php IBAN.php ISIN.php

From: Date: Sun, 16 Sep 2007 16:42:34 +0000
Subject: cvs: pear /Validate/Validate Finance.php /Validate/Validate/Finance CreditCard.php IBAN.php ISIN.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48612@lists.php.net to get a copy of this message
kguest Sun Sep 16 16:42:34 2007 UTC Modified files: /pear/Validate/Validate Finance.php /pear/Validate/Validate/Finance CreditCard.php IBAN.php ISIN.php Log: Bug #12058 coding standard errors

http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/Finance.php?r1=1.11&r2=1.12&diff_format=u Index: pear/Validate/Validate/Finance.php diff -u pear/Validate/Validate/Finance.php:1.11 pear/Validate/Validate/Finance.php:1.12 --- pear/Validate/Validate/Finance.php:1.11 Tue Nov 1 13:12:30 2005 +++ pear/Validate/Validate/Finance.php Sun Sep 16 16:42:34 2007 @@ -1,30 +1,34 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Stefan Neufeind | -// +----------------------------------------------------------------------+ -// | This source file is subject to the New BSD license, That is bundled | -// | with this package in the file LICENSE, and is available through | -// | the world-wide-web at | -// | http://www.opensource.org/licenses/bsd-license.php | -// | If you did not receive a copy of the new BSDlicense and are unable | -// | to obtain it through the world-wide-web, please send a note to | -// | pajoye@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Tomas V.V.Cox <cox@idecnet.com> | -// | Pierre-Alain Joye <pajoye@php.net> | -// +----------------------------------------------------------------------+ -// +/** + * Financial Validation Functions. + * + * PHP versions 4 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Validate + * @package Validate_Finance + * @author Tomas V.V.Cox <cox@idecnet.com> + * @author Pierre-Alain Joye <pajoye@php.net> + * @copyright 1997-2005 Stefan Neufeind + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @link http://pear.php.net/package/Validate_Finance + */ /** * Financial functions for validation and calculation * - * @category Validate - * @package Validate_Finance - * @author Stefan Neufeind <pear.neufeind@speedpartner.de> - * @copyright 2005 The PHP Group - * @license http://www.opensource.org/licenses/bsd-license.php new BSD - * @version CVS: $Id: Finance.php,v 1.11 2005/11/01 13:12:30 pajoye Exp $ - * @link http://pear.php.net/package/Validate_Finance + * @category Validate + * @package Validate_Finance + * @author Stefan Neufeind <pear.neufeind@speedpartner.de> + * @copyright 2005 The PHP Group + * @license http://www.opensource.org/licenses/bsd-license.php new BSD + * @version CVS: $Id: Finance.php,v 1.12 2007/09/16 16:42:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_Finance */ /** @@ -39,23 +43,24 @@ * - IBAN (international bankaccount number) * - Euro banknote id * - * @category Validate - * @package Validate_Finance - * @author Stefan Neufeind <neufeind@speedpartner.de> - * @copyright 1997-2005 Stefan Neufeind - * @license http://www.opensource.org/licenses/bsd-license.php new BSD - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_Finance + * @category Validate + * @package Validate_Finance + * @author Stefan Neufeind <neufeind@speedpartner.de> + * @copyright 1997-2005 Stefan Neufeind + * @license http://www.opensource.org/licenses/bsd-license.php new BSD + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_Finance */ class Validate_Finance { /** * Validation of an IBAN (international bankaccount number) * - * @param string $iban IBAN to be validated - * @access public - * @since 0.1 - * @return boolean true if IBAN is okay + * @param string $iban IBAN to be validated + * + * @access public + * @since 0.1 + * @return boolean true if IBAN is okay */ function iban($iban = '') { @@ -65,14 +70,16 @@ /** * Validation of a Euro banknote id * - * @param string $banknote Euro banknote id to be validated - * @access public - * @since 0.1 - * @return boolean true if Euro banknote id is okay + * @param string $banknote Euro banknote id to be validated + * + * @access public + * @since 0.1 + * @return boolean true if Euro banknote id is okay */ function banknoteEuro($banknote = '') { - $euro_countrycode = array('J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + $euro_countrycode = array('J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z'); if (strlen($banknote) != 12) { return false; @@ -88,13 +95,15 @@ } // build checksum, substitute and calc - $tempbanknote = str_replace($banknote_replace_chars, $banknote_replace_values, substr($banknote, 0, -1)); + $tempbanknote = str_replace($banknote_replace_chars, + $banknote_replace_values, + substr($banknote, 0, -1)); $tempcheckvalue = 0; for ($strcounter = 0; $strcounter < strlen($tempbanknote); $strcounter++) { $tempcheckvalue += intval($tempbanknote[$strcounter]); } $tempcheckvalue %= 9; // modulo 9 - $tempcheckvalue = 8 - $tempcheckvalue; + $tempcheckvalue = 8 - $tempcheckvalue; return (intval($banknote[strlen($banknote)-1]) == $tempcheckvalue); } // end func banknoteEuro http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/Finance/CreditCard.php?r1=1.12&r2=1.13&diff_format=u Index: pear/Validate/Validate/Finance/CreditCard.php diff -u pear/Validate/Validate/Finance/CreditCard.php:1.12 pear/Validate/Validate/Finance/CreditCard.php:1.13 --- pear/Validate/Validate/Finance/CreditCard.php:1.12 Tue Nov 1 13:12:31 2005 +++ pear/Validate/Validate/Finance/CreditCard.php Sun Sep 16 16:42:34 2007 @@ -1,29 +1,26 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Stefan Neufeind | -// +----------------------------------------------------------------------+ -// | This source file is subject to the New BSD license, That is bundled | -// | with this package in the file LICENSE, and is available through | -// | the world-wide-web at | -// | http://www.opensource.org/licenses/bsd-license.php | -// | If you did not receive a copy of the new BSDlicense and are unable | -// | to obtain it through the world-wide-web, please send a note to | -// | pajoye@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | -// +----------------------------------------------------------------------+ -// /** * Validation methods for credit card related data * - * @category Validate - * @package Validate_Finance_CreditCard - * @author Philippe Jausions <Philippe.Jausions@11abacus.com> - * @copyright 1997-2005 Stefan Neufeind - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: CreditCard.php,v 1.12 2005/11/01 13:12:31 pajoye Exp $ - * @link http://pear.php.net/package/Validate_Finance_CreditCard + * PHP Versions 4 and 5 + * + * This source file is subject to the New BSD license, That is bundled + * with this package in the file LICENSE, and is available through + * the world-wide-web at + * http://www.opensource.org/licenses/bsd-license.php + * If you did not receive a copy of the new BSDlicense and are unable + * to obtain it through the world-wide-web, please send a note to + * pajoye@php.net so we can mail you a copy immediately. + * + * @category Validate + * @package Validate_Finance_CreditCard + * @author Stefan Neufeind <pear.neufeind@speedpartner.de> + * @author Philippe Jausions <Philippe.Jausions@11abacus.com> + * @copyright 1997-2005 Stefan Neufeind + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: CreditCard.php,v 1.13 2007/09/16 16:42:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_Finance_CreditCard */ /** @@ -38,14 +35,14 @@ * the package does NOT check if a card is a legitimate card registered * with a card issuer, or if the card is reported stolen, etc... * - * @category Validate - * @package Validate_Finance_CreditCard - * @author Philippe Jausions <Philippe.Jausions@11abacus.com> - * @author Ondrej Jombik <nepto@pobox.sk> - * @copyright 1997-2005 Stefan Neufeind - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_Finance_CreditCard + * @category Validate + * @package Validate_Finance_CreditCard + * @author Philippe Jausions <Philippe.Jausions@11abacus.com> + * @author Ondrej Jombik <nepto@pobox.sk> + * @copyright 1997-2005 Stefan Neufeind + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_Finance_CreditCard */ class Validate_Finance_CreditCard { @@ -53,23 +50,23 @@ * Validates a number according to Luhn check algorithm * * This function checks given number according Luhn check - * algorithm. It is published on several places, also here: + * algorithm. It is published on several places. See links for details. + * + * @param string $number number to check * * @link http://www.webopedia.com/TERM/L/Luhn_formula.html * @link http://www.merriampark.com/anatomycc.htm * @link http://hysteria.sk/prielom/prielom-12.html#3 (Slovak language) * @link http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html (Perl lib) * - * @param string $number to check * @return bool TRUE if number is valid, FALSE otherwise * @access public * @static - * @author Ondrej Jombik <nepto@pobox.sk> */ function Luhn($number) { $len_number = strlen($number); - $sum = 0; + $sum = 0; for ($k = $len_number % 2; $k < $len_number; $k += 2) { if ((intval($number{$k}) * 2) > 9) { $sum += (intval($number{$k}) * 2) - 9; @@ -93,12 +90,13 @@ * This method doesn't guarantee that the card is legitimate. It merely * checks the card number passes a mathematical algorithm. * - * @param string $creditCard number (spaces and dashes tolerated) - * @param string $cardType type/brand of card (case insensitive) + * @param string $creditCard number (spaces and dashes tolerated) + * @param string $cardType type/brand of card (case insensitive) * "MasterCard", "Visa", "AMEX", "AmericanExpress", * "American Express", "Diners", "DinersClub", "Diners Club", * "CarteBlanche", "Carte Blanche", "Discover", "JCB", * "EnRoute", "Eurocard", "Eurocard/MasterCard". + * * @return bool TRUE if number is valid, FALSE otherwise * @access public * @static @@ -143,12 +141,13 @@ * For instance, if a $card is a MasterCard, type($card, 'EuroCard') * will also return true. * - * @param string $creditCard number (spaces and dashes tolerated) - * @param string $cardType type/brand of card (case insensitive) + * @param string $creditCard number (spaces and dashes tolerated) + * @param string $cardType type/brand of card (case insensitive) * "MasterCard", "Visa", "AMEX", "AmericanExpress", * "American Express", "Diners", "DinersClub", "Diners Club", * "CarteBlanche", "Carte Blanche", "Discover", "JCB", * "EnRoute", "Eurocard", "Eurocard/MasterCard". + * * @return bool TRUE is type matches, FALSE otherwise * @access public * @static @@ -157,37 +156,37 @@ function type($creditCard, $cardType) { switch (strtoupper($cardType)) { - case 'MASTERCARD': - case 'EUROCARD': - case 'EUROCARD/MASTERCARD': - $regex = '5[1-5][0-9]{14}'; - break; - case 'VISA': - $regex = '4([0-9]{12}|[0-9]{15})'; - break; - case 'AMEX': - case 'AMERICANEXPRESS': - case 'AMERICAN EXPRESS': - $regex = '3[47][0-9]{13}'; - break; - case 'DINERS': - case 'DINERSCLUB': - case 'DINERS CLUB': - case 'CARTEBLANCHE': - case 'CARTE BLANCHE': - $regex = '3(0[0-5][0-9]{11}|[68][0-9]{12})'; - break; - case 'DISCOVER': - $regex = '6011[0-9]{12}'; - break; - case 'JCB': - $regex = '(3[0-9]{15}|(2131|1800)[0-9]{11})'; - break; - case 'ENROUTE': - $regex = '2(014|149)[0-9]{11}'; - break; - default: - return false; + case 'MASTERCARD': + case 'EUROCARD': + case 'EUROCARD/MASTERCARD': + $regex = '5[1-5][0-9]{14}'; + break; + case 'VISA': + $regex = '4([0-9]{12}|[0-9]{15})'; + break; + case 'AMEX': + case 'AMERICANEXPRESS': + case 'AMERICAN EXPRESS': + $regex = '3[47][0-9]{13}'; + break; + case 'DINERS': + case 'DINERSCLUB': + case 'DINERS CLUB': + case 'CARTEBLANCHE': + case 'CARTE BLANCHE': + $regex = '3(0[0-5][0-9]{11}|[68][0-9]{12})'; + break; + case 'DISCOVER': + $regex = '6011[0-9]{12}'; + break; + case 'JCB': + $regex = '(3[0-9]{15}|(2131|1800)[0-9]{11})'; + break; + case 'ENROUTE': + $regex = '2(014|149)[0-9]{11}'; + break; + default: + return false; } $regex = '/^' . $regex . '$/'; @@ -217,11 +216,12 @@ * * This method returns FALSE for card types that don't support CVV. * - * @param string $cvv value to verify - * @param string $cardType type/brand of card (case insensitive) + * @param string $cvv value to verify + * @param string $cardType type/brand of card (case insensitive) * "MasterCard", "Visa", "AMEX", "AmericanExpress", * "American Express", "Discover", "Eurocard/MasterCard", * "Eurocard" + * * @return bool TRUE if format is correct, FALSE otherwise * @access public * @static @@ -229,20 +229,20 @@ function cvv($cvv, $cardType) { switch (strtoupper($cardType)) { - case 'MASTERCARD': - case 'EUROCARD': - case 'EUROCARD/MASTERCARD': - case 'VISA': - case 'DISCOVER': - $digits = 3; - break; - case 'AMEX': - case 'AMERICANEXPRESS': - case 'AMERICAN EXPRESS': - $digits = 4; - break; - default: - return false; + case 'MASTERCARD': + case 'EUROCARD': + case 'EUROCARD/MASTERCARD': + case 'VISA': + case 'DISCOVER': + $digits = 3; + break; + case 'AMEX': + case 'AMERICANEXPRESS': + case 'AMERICAN EXPRESS': + $digits = 4; + break; + default: + return false; } if (strlen($cvv) == $digits @@ -254,4 +254,4 @@ } } -?> \ No newline at end of file +?> http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/Finance/IBAN.php?r1=1.20&r2=1.21&diff_format=u Index: pear/Validate/Validate/Finance/IBAN.php diff -u pear/Validate/Validate/Finance/IBAN.php:1.20 pear/Validate/Validate/Finance/IBAN.php:1.21 --- pear/Validate/Validate/Finance/IBAN.php:1.20 Sat Jun 9 15:13:32 2007 +++ pear/Validate/Validate/Finance/IBAN.php Sun Sep 16 16:42:34 2007 @@ -1,29 +1,25 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Stefan Neufeind | -// +----------------------------------------------------------------------+ -// | This source file is subject to the New BSD license, That is bundled | -// | with this package in the file LICENSE, and is available through | -// | the world-wide-web at | -// | http://www.opensource.org/licenses/bsd-license.php | -// | If you did not receive a copy of the new BSDlicense and are unable | -// | to obtain it through the world-wide-web, please send a note to | -// | pajoye@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | -// +----------------------------------------------------------------------+ -// /** * Methods for common data validations * - * @category Validate - * @package Validate_Finance_IBAN - * @author Stefan Neufeind <pear.neufeind@speedpartner.de> - * @copyright 2005 The PHP Group - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: IBAN.php,v 1.20 2007/06/09 15:13:32 davidc Exp $ - * @link http://pear.php.net/package/Validate_Finance_IBAN + * PHP Versions 4 and 5 + * + * This source file is subject to the New BSD license, That is bundled + * with this package in the file LICENSE, and is available through + * the world-wide-web at + * http://www.opensource.org/licenses/bsd-license.php + * If you did not receive a copy of the new BSDlicense and are unable + * to obtain it through the world-wide-web, please send a note to + * pajoye@php.net so we can mail you a copy immediately. + * + * @category Validate + * @package Validate_Finance_IBAN + * @author Stefan Neufeind <pear.neufeind@speedpartner.de> + * @copyright 1997-2005 Stefan Neufeind + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: IBAN.php,v 1.21 2007/09/16 16:42:34 kguest Exp $ + * @link http://pear.php.net/package/Validate_Finance_IBAN */ @@ -33,26 +29,27 @@ * sure to add the textual messages to the IBAN::errorMessage() function as well */ -define('VALIDATE_FINANCE_IBAN_OK', 1); -define('VALIDATE_FINANCE_IBAN_ERROR', -1); -define('VALIDATE_FINANCE_IBAN_GENERAL_INVALID', -2); -define('VALIDATE_FINANCE_IBAN_TOO_SHORT', -4); -define('VALIDATE_FINANCE_IBAN_TOO_LONG', -5); -define('VALIDATE_FINANCE_IBAN_COUNTRY_INVALID', -6); -define('VALIDATE_FINANCE_IBAN_INVALID_FORMAT', -7); // tested via regex; e.g. if un-allowed characters in IBAN -define('VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID', -8); +define('VALIDATE_FINANCE_IBAN_OK', 1); +define('VALIDATE_FINANCE_IBAN_ERROR', -1); +define('VALIDATE_FINANCE_IBAN_GENERAL_INVALID', -2); +define('VALIDATE_FINANCE_IBAN_TOO_SHORT', -4); +define('VALIDATE_FINANCE_IBAN_TOO_LONG', -5); +define('VALIDATE_FINANCE_IBAN_COUNTRY_INVALID', -6); +// tested via regex; e.g. if un-allowed characters in IBAN +define('VALIDATE_FINANCE_IBAN_INVALID_FORMAT', -7); +define('VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID', -8); /** * Validate and process IBAN (international bank account numbers) * - * @category Validate - * @package Validate_Finance_IBAN - * @author Stefan Neufeind <neufeind@speedpartner.de> - * @copyright 2005 The PHP Group - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate - * @link Ireland IBANs http://www.skynet.ie/~martin/pages/iban.html + * @category Validate + * @package Validate_Finance_IBAN + * @author Stefan Neufeind <neufeind@speedpartner.de> + * @copyright 2005 The PHP Group + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate + * @link Ireland IBANs http://www.skynet.ie/~martin/pages/iban.html */ class Validate_Finance_IBAN { @@ -71,7 +68,9 @@ var $_errorcode = 0; /** - * List of all IBAN countrycodes; also gives corresponding countrynames (in long form) + * List of all IBAN countrycodes; also gives corresponding countrynames (in + * long form) + * * @return array * @access private */ @@ -127,6 +126,7 @@ /** * List of IBAN length; can be used for a quick check + * * @return array * @access private */ @@ -181,7 +181,9 @@ } /** - * List of where the bankcode inside an IBAN starts (starting from 0) and its length + * List of where the bankcode inside an IBAN starts (starting from 0) and + * its length + * * @return array * @access private */ @@ -191,52 +193,69 @@ if (!isset($_iban_countrycode_bankcode)) { $_iban_countrycode_bankcode = array( - 'AD' => array('start' => 4, 'length' => 8), // first 4 chars bankcode, last 4 chars branch + //AD: first 4 chars bankcode, last 4 chars branch + 'AD' => array('start' => 4, 'length' => 8), 'AT' => array('start' => 4, 'length' => 5), - 'BA' => array('start' => 4, 'length' => 6), // first 3 chars bankcode, last 3 chars branch + //BA: first 3 chars bankcode, last 3 chars branch + 'BA' => array('start' => 4, 'length' => 6), 'BE' => array('start' => 4, 'length' => 3), 'BG' => array('start' => 4, 'length' => 8), 'CH' => array('start' => 4, 'length' => 5), 'CS' => array('start' => 4, 'length' => 3), - 'CY' => array('start' => 4, 'length' => 8), // first 3 chars bankcode, last 5 chars branch + //CY: first 3 chars bankcode, last 5 chars branch + 'CY' => array('start' => 4, 'length' => 8), 'CZ' => array('start' => 4, 'length' => 4), 'DE' => array('start' => 4, 'length' => 8), 'DK' => array('start' => 4, 'length' => 4), - 'EE' => array('start' => 4, 'length' => 4), // first 2 chars bankidentifier, last 2 chars bankcode - 'ES' => array('start' => 4, 'length' => 8), // followed by 2 chars (checksum) + //EE: first 2 chars bankidentifier, last 2 chars bankcode + 'EE' => array('start' => 4, 'length' => 4), + // ES: followed by 2 chars (checksum) + 'ES' => array('start' => 4, 'length' => 8), 'FR' => array('start' => 4, 'length' => 10), 'FI' => array('start' => 4, 'length' => 6), - 'GB' => array('start' => 4, 'length' => 10), // first 4 chars bankidentifier, last 6 chars bank-branchcode + //GB: first 4 chars bankidentifier, last 6 chars bank-branchcode + 'GB' => array('start' => 4, 'length' => 10), 'GI' => array('start' => 4, 'length' => 4), - 'GR' => array('start' => 4, 'length' => 7), // first 3 chars bankcode, last 4 chars branch + //GR: first 3 chars bankcode, last 4 chars branch + 'GR' => array('start' => 4, 'length' => 7), 'HR' => array('start' => 4, 'length' => 7), - 'HU' => array('start' => 4, 'length' => 7), // first 3 chars bankcode, last 4 chars branch, followed by 1 char (checksum) - 'IE' => array('start' => 4, 'length' => 10), // first 4 chars bankcode, last 6 chars branch + //HU: first 3 chars bankcode, last 4 chars branch, + //followed by 1 char (checksum) + 'HU' => array('start' => 4, 'length' => 7), + //IE: first 4 chars bankcode, last 6 chars branch + 'IE' => array('start' => 4, 'length' => 10), 'IS' => array('start' => 4, 'length' => 4), 'IT' => array('start' => 4, 'length' => 11), - 'LI' => array('start' => 4, 'length' => 5), // bankcode and branch + //LI: bankcode and branch + 'LI' => array('start' => 4, 'length' => 5), 'LT' => array('start' => 4, 'length' => 5), 'LU' => array('start' => 4, 'length' => 3), 'LV' => array('start' => 4, 'length' => 4), 'MK' => array('start' => 4, 'length' => 3), - 'MT' => array('start' => 4, 'length' => 9), // first 4 chars bankidentifier, last 5 chars bank sort code + //MT: first 4 chars bankidentifier, last 5 chars bank sort code + 'MT' => array('start' => 4, 'length' => 9), 'NL' => array('start' => 4, 'length' => 4), 'NO' => array('start' => 4, 'length' => 4), 'PL' => array('start' => 4, 'length' => 8), 'PT' => array('start' => 4, 'length' => 8), 'RO' => array('start' => 4, 'length' => 4), - 'SE' => array('start' => 4, 'length' => 3), // bankcode and branch + //SE: bankcode and branch + 'SE' => array('start' => 4, 'length' => 3), 'SI' => array('start' => 4, 'length' => 5), 'SK' => array('start' => 4, 'length' => 4), - 'TN' => array('start' => 4, 'length' => 5), // first 2 chars bankcode, last 3 chars branch - 'TR' => array('start' => 4, 'length' => 5), // followed by 1 char (reserved field) + //TN: first 2 chars bankcode, last 3 chars branch + 'TN' => array('start' => 4, 'length' => 5), + //TR: followed by 1 char (reserved field) + 'TR' => array('start' => 4, 'length' => 5), ); } return $_iban_countrycode_bankcode; } /** - * List of where the bankaccount-number inside an IBAN starts (starting from 0) and its length + * List of where the bankaccount-number inside an IBAN starts (starting from 0) + * and its length + * * @return array * @access private */ @@ -248,42 +267,58 @@ array( 'AD' => array('start' => 12, 'length' => 12), 'AT' => array('start' => 9, 'length' => 11), - 'BA' => array('start' => 10, 'length' => 8), // followed by 2 chars (checksum) - 'BE' => array('start' => 7, 'length' => 7), // followed by 2 chars (checksum) + //BA: followed by 2 chars (checksum) + 'BA' => array('start' => 10, 'length' => 8), + //BE: followed by 2 chars (checksum) + 'BE' => array('start' => 7, 'length' => 7), 'BG' => array('start' => 12, 'length' => 10), 'CH' => array('start' => 9, 'length' => 12), - 'CS' => array('start' => 7, 'length' => 13), // followed by 2 chars (checksum) + //CS: followed by 2 chars (checksum) + 'CS' => array('start' => 7, 'length' => 13), 'CY' => array('start' => 12, 'length' => 16), 'CZ' => array('start' => 8, 'length' => 16), 'DE' => array('start' => 12, 'length' => 10), - 'DK' => array('start' => 8, 'length' => 9), // followed by 1 char (checksum) - 'EE' => array('start' => 8, 'length' => 11), // followed by 1 char (checksum) + //DK: followed by 1 char (checksum) + 'DK' => array('start' => 8, 'length' => 9), + //EE: followed by 1 char (checksum) + 'EE' => array('start' => 8, 'length' => 11), 'ES' => array('start' => 14, 'length' => 10), - 'FR' => array('start' => 14, 'length' => 11), // followed by 2 chars (checksum) - 'FI' => array('start' => 10, 'length' => 7), // followed by 1 char (checksum) + //FR: followed by 2 chars (checksum) + 'FR' => array('start' => 14, 'length' => 11), + //FI: followed by 1 char (checksum) + 'FI' => array('start' => 10, 'length' => 7), 'GB' => array('start' => 14, 'length' => 8), 'GI' => array('start' => 8, 'length' => 15), 'GR' => array('start' => 11, 'length' => 16), 'HR' => array('start' => 11, 'length' => 10), - 'HU' => array('start' => 12, 'length' => 15), // followed by 1 char (checksum) + //HU: followed by 1 char (checksum) + 'HU' => array('start' => 12, 'length' => 15), 'IE' => array('start' => 14, 'length' => 8), - 'IS' => array('start' => 8, 'length' => 18), // 2 accounttype, 6 account number, 10 identification number + //IS: 2 accounttype, 6 account number, 10 identification number + 'IS' => array('start' => 8, 'length' => 18), 'IT' => array('start' => 15, 'length' => 12), 'LI' => array('start' => 9, 'length' => 12), 'LT' => array('start' => 9, 'length' => 11), 'LU' => array('start' => 7, 'length' => 13), 'LV' => array('start' => 8, 'length' => 13), - 'MK' => array('start' => 7, 'length' => 10), // followed by 2 chars (checksum) + //MK: followed by 2 chars (checksum) + 'MK' => array('start' => 7, 'length' => 10), 'MT' => array('start' => 13, 'length' => 18), 'NL' => array('start' => 8, 'length' => 10), - 'NO' => array('start' => 8, 'length' => 6), // followed by 1 char (checksum) + //NO: followed by 1 char (checksum) + 'NO' => array('start' => 8, 'length' => 6), 'PL' => array('start' => 12, 'length' => 16), - 'PT' => array('start' => 12, 'length' => 11), // followed by 2 chars (checksum) - 'RO' => array('start' => 8, 'length' => 16), // branch and client account identifier - 'SE' => array('start' => 7, 'length' => 16), // followed by 1 char (checksum) - 'SI' => array('start' => 9, 'length' => 8), // followed by 2 chars (checksum) + //PT: followed by 2 chars (checksum) + 'PT' => array('start' => 12, 'length' => 11), + // branch and client account identifier + 'RO' => array('start' => 8, 'length' => 16), + //SE: followed by 1 char (checksum) + 'SE' => array('start' => 7, 'length' => 16), + //SI: followed by 2 chars (checksum) + 'SI' => array('start' => 9, 'length' => 8), 'SK' => array('start' => 8, 'length' => 16), - 'TN' => array('start' => 9, 'length' => 13), // followed by 2 chars (checksum) + //TN: followed by 2 chars (checksum) + 'TN' => array('start' => 9, 'length' => 13), 'TR' => array('start' => 10, 'length' => 16), ); } @@ -292,6 +327,7 @@ /** * List of regex for validating an IBAN according to standards for each country + * * @return array * @access private */ @@ -347,14 +383,16 @@ /** * Class constructor - * @param string $iban IBAN to be validated / processed + * + * @param string $iban IBAN to be validated / processed + * * @access public */ function Validate_Finance_IBAN($iban = '') { - $iban = strtoupper($iban); + $iban = strtoupper($iban); $this->_iban = $iban; - } // end constructor + } /** * Returns the current IBAN @@ -370,20 +408,22 @@ /** * Sets the current IBAN to a new value * - * @param string $iban IBAN to be validated / processed + * @param string $iban IBAN to be validated / processed + * * @access public * @return void */ function setIBAN($iban = '') { - $iban = strtoupper($iban); + $iban = strtoupper($iban); $this->_iban = $iban; - } // end func setIBAN + } /** * Performs validation of the IBAN * - * @param string $arg optional parameter for calling validate as a static function + * @param string $arg optional parameter for calling validate as static function + * * @access public * @return boolean true if no error found */ @@ -395,7 +435,7 @@ $iban = $arg; } - $errorcode=VALIDATE_FINANCE_IBAN_OK; + $errorcode = VALIDATE_FINANCE_IBAN_OK; static $_iban_countrycode_countryname; if (!isset($_iban_countrycode_countryname)) { @@ -403,52 +443,55 @@ } static $_iban_countrycode_length; if (!isset($_iban_countrycode_length)) { - $_iban_countrycode_ibanlength = Validate_Finance_IBAN::_getCountrycodeIBANLength(); + $_iban_countrycode_ibanlength = Validate_Finance_IBAN::_getCountrycodeIBANLength(); } static $_iban_countrycode_regex; if (!isset($_iban_countrycode_regex)) { - $_iban_countrycode_regex = Validate_Finance_IBAN::_getCountrycodeRegex(); + $_iban_countrycode_regex = Validate_Finance_IBAN::_getCountrycodeRegex(); } if (strlen($iban) <= 4) { $errorcode = VALIDATE_FINANCE_IBAN_TOO_SHORT; - } elseif (!isset( $_iban_countrycode_countryname[ substr($iban,0,2) ] )) { + } elseif (!isset( $_iban_countrycode_countryname[substr($iban, 0, 2)])) { $errorcode = VALIDATE_FINANCE_IBAN_COUNTRY_INVALID; - } elseif (strlen($iban) < $_iban_countrycode_ibanlength[ substr($iban,0,2) ]) { + } elseif (strlen($iban) < $_iban_countrycode_ibanlength[substr($iban, 0, 2)]) { $errorcode = VALIDATE_FINANCE_IBAN_TOO_SHORT; - } elseif (strlen($iban) > $_iban_countrycode_ibanlength[ substr($iban,0,2) ]) { + } elseif (strlen($iban) > $_iban_countrycode_ibanlength[substr($iban, 0, 2)]) { $errorcode = VALIDATE_FINANCE_IBAN_TOO_LONG; - } elseif (!preg_match($_iban_countrycode_regex[ substr($iban,0,2) ],$iban)) { + } elseif (!preg_match($_iban_countrycode_regex[substr($iban, 0, 2)], $iban)) { $errorcode = VALIDATE_FINANCE_IBAN_INVALID_FORMAT; } else { // todo: maybe implement direct checks for bankcodes of certain countries // let's see if checksum is also correct - $iban_replace_chars = range('A','Z'); - foreach (range(10,35) as $tempvalue) { - $iban_replace_values[]=strval($tempvalue); + $iban_replace_chars = range('A', 'Z'); + foreach (range(10, 35) as $tempvalue) { + $iban_replace_values[] = strval($tempvalue); } // move first 4 chars (countrycode and checksum) to the end of the string - $tempiban = substr($iban, 4).substr($iban, 0, 4); - $tempiban = str_replace($iban_replace_chars, $iban_replace_values, $tempiban); + $tempiban = substr($iban, 4) . substr($iban, 0, 4); + $tempiban = str_replace($iban_replace_chars, + $iban_replace_values, + $tempiban); + $tempcheckvalue = intval(substr($tempiban, 0, 1)); for ($strcounter = 1; $strcounter < strlen($tempiban); $strcounter++) { $tempcheckvalue *= 10; - $tempcheckvalue += intval(substr($tempiban,$strcounter,1)); + $tempcheckvalue += intval(substr($tempiban, $strcounter, 1)); $tempcheckvalue %= 97; } // checkvalue of 1 indicates correct IBAN checksum if ($tempcheckvalue != 1) { - $errorcode=VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID; + $errorcode = VALIDATE_FINANCE_IBAN_CHECKSUM_INVALID; } else { - $errorcode=VALIDATE_FINANCE_IBAN_OK; + $errorcode = VALIDATE_FINANCE_IBAN_OK; } } if (isset($this)) { - $this->_errorcode=$errorcode; + $this->_errorcode = $errorcode; } return ($errorcode == VALIDATE_FINANCE_IBAN_OK); } // end func validate @@ -474,10 +517,15 @@ { if (strlen($this->_iban)>4) { // return first two characters - return substr($this->_iban,0,2); + return substr($this->_iban, 0, 2); } else { $this->_errorcode = VALIDATE_FINANCE_IBAN_TOO_SHORT; - return PEAR::raiseError($this->errorMessage($this->_errorcode), $this->_errorcode, PEAR_ERROR_TRIGGER, E_USER_WARNING, $this->errorMessage($this->_errorcode)." in VALIDATE_FINANCE_IBAN::getCountrycode()"); + $msg = $this->errorMessage($this->_errorcode); + return PEAR::raiseError($msg, + $this->_errorcode, + PEAR_ERROR_TRIGGER, + E_USER_WARNING, + "$msg in VALIDATE_FINANCE_IBAN::getCountrycode()"); } } // end func getCountrycode @@ -508,11 +556,19 @@ { if (!$this->validate()) { $this->_errorcode = VALIDATE_FINANCE_IBAN_GENERAL_INVALID; - return PEAR::raiseError($this->errorMessage($this->_errorcode), $this->_errorcode, PEAR_ERROR_TRIGGER, E_USER_WARNING, $this->errorMessage($this->_errorcode)." in VALIDATE_FINANCE_IBAN::getBankcode()"); + $msg = $this->errorMessage($this->_errorcode); + return PEAR::raiseError($msg, + $this->_errorcode, + PEAR_ERROR_TRIGGER, + E_USER_WARNING, + "$msg in VALIDATE_FINANCE_IBAN::getBankcode()"); } else { $_iban_countrycode_bankcode = Validate_Finance_IBAN::_getCountrycodeBankcode(); - $currCountrycodeBankcode = $_iban_countrycode_bankcode[ substr($this->_iban,0,2) ]; - return substr($this->_iban, $currCountrycodeBankcode['start'], $currCountrycodeBankcode['length']); + $position = substr($this->_iban, 0, 2); + $currCountrycodeBankcode = $_iban_country_code_bankcode[$position]; + return substr($this->_iban, + $currCountrycodeBankcode['start'], + $currCountrycodeBankcode['length']); } } // end func getBankcode @@ -526,19 +582,29 @@ { if (!$this->validate()) { $this->_errorcode = VALIDATE_FINANCE_IBAN_GENERAL_INVALID; - return PEAR::raiseError($this->errorMessage($this->_errorcode), $this->_errorcode, PEAR_ERROR_TRIGGER, E_USER_WARNING, $this->errorMessage($this->_errorcode)." in VALIDATE_FINANCE_IBAN::getBankaccount()"); + //get error message + $msg = $this->errorMessage($this->_errorcode); + return PEAR::raiseError($msg, + $this->_errorcode, + PEAR_ERROR_TRIGGER, + E_USER_WARNING, + "$msg in VALIDATE_FINANCE_IBAN::getBankaccount()"); } else { $_iban_countrycode_bankaccount = Validate_Finance_IBAN::_getCountrycodeBankaccount(); - $currCountrycodeBankaccount = $_iban_countrycode_bankaccount[ substr($this->_iban,0,2) ]; - return substr($this->_iban, $currCountrycodeBankaccount['start'], $currCountrycodeBankaccount['length']); + //extract details + $currCountrycodeBankaccount = $_iban_countrycode_bankaccount[substr($this->_iban, 0, 2)]; + return substr($this->_iban, + $currCountrycodeBankaccount['start'], + $currCountrycodeBankaccount['length']); } } // end func getAccount /** * Return a textual error message for an IBAN error code * + * @param int $value error code + * * @access public - * @param int error code * @return string error message */ function errorMessage($value) http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/Finance/ISIN.php?r1=1.1&r2=1.2&diff_format=u Index: pear/Validate/Validate/Finance/ISIN.php diff -u pear/Validate/Validate/Finance/ISIN.php:1.1 pear/Validate/Validate/Finance/ISIN.php:1.2 --- pear/Validate/Validate/Finance/ISIN.php:1.1 Thu Jan 18 20:01:11 2007 +++ pear/Validate/Validate/Finance/ISIN.php Sun Sep 16 16:42:34 2007 @@ -13,21 +13,33 @@ * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * - * @category Validate - * @package Validate_Finance_ISIN - * @author Stephan Jakoubek <stephan-pear@jakoubek.de> - * @author Uli Honal <uli@netzgeist.de> - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @category Validate + * @package Validate_Finance_ISIN + * @author Stephan Jakoubek <stephan-pear@jakoubek.de> + * @author Uli Honal <uli@netzgeist.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @link http://pear.php.net/package/Validate_Finance */ +/** + * Validate_Finance_ISIN + * + * @category Validate + * @package Validate_Finance_ISIN + * @author Stephan Jakoubek <stephan-pear@jakoubek.de> + * @author Uli Honal <uli@netzgeist.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @link http://pear.php.net/package/Validate_Finance + */ class Validate_Finance_ISIN { /** * Validate an ISIN (International Securities Identification Number, ISO 6166) * - * @param string $isin ISIN to be validated - * @access public - * @return boolean true if ISIN is valid + * @param string $isin ISIN to be validated + * + * @access public + * @return boolean true if ISIN is valid */ function validate($isin) { @@ -44,8 +56,8 @@ // Calculate double-add-double checksum. $checksum = 0; - $len = strlen($base10) - 1; - $parity = $len % 2; + $len = strlen($base10) - 1; + $parity = $len % 2; // Iterate over every digit, starting with the rightmost (=check digit). for ($i = $len; $i >= 0; $i--) { // Multiply every other digit by two.
« previous php.pear.cvs (#48612) next »