cvs: pear /Validate/Validate IE.php

From: Date: Thu, 05 Jul 2007 12:39:15 +0000
Subject: cvs: pear /Validate/Validate IE.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-47868@lists.php.net to get a copy of this message
kguest Thu Jul 5 12:39:15 2007 UTC Modified files: /pear/Validate/Validate IE.php Log: Bug #11531 using phpcs [php codesniffer] highlights a multitude of CS errors.

http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/IE.php?r1=1.16&r2=1.17&diff_format=u Index: pear/Validate/Validate/IE.php diff -u pear/Validate/Validate/IE.php:1.16 pear/Validate/Validate/IE.php:1.17 --- pear/Validate/Validate/IE.php:1.16 Thu Jul 5 07:39:27 2007 +++ pear/Validate/Validate/IE.php Thu Jul 5 12:39:15 2007 @@ -22,7 +22,7 @@ * @author David Coallier <davidc@php.net> * @copyright 1997-2007 Agora Production (http://agoraproduction.com) * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: IE.php,v 1.16 2007/07/05 07:39:27 kguest Exp $ + * @version CVS: $Id: IE.php,v 1.17 2007/07/05 12:39:15 kguest Exp $ * @link http://pear.php.net/package/Validate_IE */ @@ -32,14 +32,14 @@ * This class provides methods to validate: * - Postal code * - * @category Validate - * @package Validate_IE - * @author David Coallier <davidc@php.net> - * @author Ken Guest <ken@linux.ie> - * @copyright 1997-2007 Agora Production (http://agoraproduction.com) - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_IE + * @category Validate + * @package Validate_IE + * @author David Coallier <davidc@php.net> + * @author Ken Guest <ken@linux.ie> + * @copyright 1997-2007 Agora Production (http://agoraproduction.com) + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_IE */ class Validate_IE { @@ -47,10 +47,11 @@ /** * Validate an Irish SWIFT code * - * @access public - * @param string $swift swift code + * @param string $swift swift code + * * @return bool true if number is valid, false if not. * @static + * @access public */ function swift($swift) { @@ -61,10 +62,11 @@ /** * Validate Irish IBAN * - * @access public - * @param string The account number to be validated - * @param string swift code to compare against IBAN + * @param string $iban The account number to be validated + * @param string $swift swift code to compare against IBAN + * * @return bool + * @access public */ function IBAN($iban, $swift = false) { @@ -77,7 +79,7 @@ if (substr($iban, 0, 2) == 'IE') { if (is_readable('Validate/Finance/IBAN.php')) { - require 'Validate/Finance/IBAN.php'; + include 'Validate/Finance/IBAN.php'; return Validate_Finance_IBAN::validate($iban); } } @@ -93,6 +95,9 @@ * You can either use the requiredAreaCode or not. * by default this is set to true. * + * @param string $number The phone number + * @param bool $requiredAreaCode defaults to true - to require area code checks + * * <code> * <?php * // Include the package @@ -114,14 +119,7 @@ * ?> * </code> * - * - * @note Irish phone numbers are not the same than UK Phone numbers - * Irish phone numbers are much less complex as UK now has per - * district phone numbers etc. - * * @access public - * @param string $number The phone number - * @param bool $requiredAreaCode defaults to true. If set require area code checking. * @return bool true if number is valid, false if not. * @static */ @@ -131,6 +129,9 @@ * categorize prefixes into landline, mobile and 'other' * each prefix has an associated regular expression. * use defaultRegExp if associated entry is empty. + * @note Irish phone numbers are not the same as UK Phone numbers; + * Irish phone numbers are much less complex as UK now has per + * district phone numbers etc. */ static $defaultRegExp = '/^\d{7,10}$/'; static $irishLandLine = array( @@ -167,7 +168,7 @@ '1890'=>'/^1890[0-9]{6}$/'); if (preg_match('/^00.*$/', $number)) { - $number = '+' . substr($number,2); + $number = '+' . substr($number, 2); } $number = str_replace(array('(', ')', '-', '+', '.', ' '), '', $number); //remove country code for Ireland and insert leading zero of area code. @@ -187,8 +188,8 @@ return false; } //check special rate numbers - if (($requiredAreaCode) && (substr($number,0,1) == '1')) { - $prefix = substr($number, 0,4); + if (($requiredAreaCode) && (substr($number, 0, 1) == '1')) { + $prefix = substr($number, 0, 4); if (isset($irishOtherRates[$prefix])) { $reg = $irishOtherRates[$prefix]; return (preg_match($reg, $number)); @@ -201,20 +202,20 @@ //if number has ten digits and a prefix it's likely a mobile phone if (($requiredAreaCode) && ($len == 10)) { - $prefix = substr($number, 1,2); + $prefix = substr($number, 1, 2); if (isset($irishMobileAreas[$prefix])) { $regexp = $irishMobileAreas[$prefix]; - if (preg_match($regexp,$number)) { + if (preg_match($regexp, $number)) { return true; } } } //see if it's a mobile phone with a 'direct to voicemail' prefix. if (($requiredAreaCode) && ($len == 11)) { - $prefix = substr($number, 1,2); + $prefix = substr($number, 1, 2); if (isset($irishMobileAreasVoiceMail[$prefix])) { $regexp = $irishMobileAreasVoiceMail[$prefix]; - if (preg_match($regexp,$number)) { + if (preg_match($regexp, $number)) { return true; } } @@ -230,9 +231,9 @@ } } else { $ret = false; - for($i = 3; $i > 0; $i--){ - $prefix = substr($number, 1,$i); - $preg = ""; + for ($i = 3; $i > 0; $i--) { + $prefix = substr($number, 1, $i); + $preg = ""; if (isset($irishLandLine[$prefix])) { $preg = $irishLandLine[$prefix]; if ($preg == '') { @@ -256,20 +257,21 @@ /** * Validate postal code * - * This function validate postal codes in Ireland - * @note Postal codes in Dublin, not in the whole country. - * http://en.wikipedia.org/wiki/List_of_Dublin_postal_districts + * This function validates postal district codes in Dublin. + * It will be revised when national postal codes are rolled out. + * + * @param string $postalCode The postal code to validate * * @access public - * @param string $postalCode The postal code to validate + * @link http://en.wikipedia.org/wiki/List_of_Dublin_postal_districts * @return bool true if postcode is ok, false otherwise */ function postalCode($postalCode) { $postalCode = strtoupper(str_replace(' ', '', trim($postalCode))); - $postalCode = str_replace('DUBLIN','D', $postalCode); + $postalCode = str_replace('DUBLIN', 'D', $postalCode); - $file = '@DATADIR@/Validate_IE/data/IE_postcodes.txt'; + $file = '@DATADIR@/Validate_IE/data/IE_postcodes.txt'; $postcodes = array_map('trim', file($file)); return in_array($postalCode, $postcodes); } @@ -280,8 +282,9 @@ * * Validate an irish passport number. * + * @param string $pp The passport number to validate. + * * @access public - * @param string $pp The passport number to validate. * @return bool If the passport number is valid or not. */ function passport($pp) @@ -300,11 +303,11 @@ /** * Validates an Irish driving licence * - * This function will validate the drivers - * licence for irish licences. + * This function will validate the number on an Irish driving licence. + * + * @param string $dl The drivers licence to validate * * @access public - * @param string $dl The drivers licence to validate * @return bool true if it validates false if it doesn't. */ function drive($dl) @@ -320,7 +323,8 @@ /** * Validate an Irish vehicle's license plate/registration number. * - * @param string $number value to validate. + * @param string $number value to validate. + * * @access public * @return bool true on success; else false. */ @@ -330,7 +334,7 @@ $plate = strtoupper($number); $regex = "/^\d{2}[\ -]([A-Z][A-Z]?)[\ -]\d{1,6}$/"; - if (preg_match($regex, $plate, $matches)){ + if (preg_match($regex, $plate, $matches)) { $mark = strtoupper($matches[1]); //check valid index mark $marks = array('C','CE','CN','CW','D','DL','G','KE','KK','KY','L', @@ -341,11 +345,11 @@ //two pre-1987 codes are still in use. ZZ and ZV. //format is ZZ nnnnn - 5 digits for ZZ code and as few as 4 for ZV $regex = "/^ZZ[\ -]\d{5}$/"; - if (preg_match($regex, $plate)){ + if (preg_match($regex, $plate)) { return true; } $regex = "/^ZV[\ -]\d{4,5}$/"; - if (preg_match($regex, $plate)){ + if (preg_match($regex, $plate)) { return true; } return false; @@ -359,14 +363,15 @@ * This function will validate a bank account * number for irish banks. * + * @param string $ac The account number + * @param string $noSort Don't validate the sort codes, optional (default: false) + * * @access public - * @param string $ac The account number - * @param string optional $noSort Do not validate the sort codes (default: false) - * @return bool true if the account validates + * @return bool true if the account validates */ function bankAC($ac, $noSort = false) { - $ac = str_replace(array('-', ' '), '', $ac); + $ac = str_replace(array('-', ' '), '', $ac); $preg = "/^\d{14}$/"; if ($noSort) { @@ -385,10 +390,11 @@ * Ireland does not have a social security number system, * the closest equivalent is a Personal Public Service Number. * + * @param string $ssn ssn number to validate + * * @link http://en.wikipedia.org/wiki/Personal_Public_Service_Number * @access public * @see Validate_IE::ppsn() - * @param string $ssn; ssn number to validate * @return bool Returns true on success, false otherwise */ function ssn($ssn) @@ -396,19 +402,20 @@ return Validate_IE::ppsn($ssn); } // }}} - // {{{ public function check_mod23 + // {{{ public function checkMOD23 /** - * check_mod23 + * Return true if the checksum in the specified PPSN is valid. * - * @param string $ppsn + * @param string $ppsn The PPS number. + * * @access public * @return boolean */ - function check_mod23($ppsn) + function checkMOD23($ppsn) { - $total=0; - for($i=0;$i<7;++$i) { - $total+=(int)$ppsn[$i]*(8-$i); + $total = 0; + for ($i = 0;$i<7;++$i) { + $total += (int)$ppsn[$i]*(8-$i); } return (int) (chr(64+($total%23)) == strtoupper($ppsn[7])); @@ -421,8 +428,9 @@ * Ireland does not have a social security number system, * the closest equivalent is a Personal Public Service Number. * + * @param string $ppsn Personal Public Service Number + * * @access public - * @param $ppsn Personal Public Service Number * @return bool Returns true on success, false otherwise * @link http://en.wikipedia.org/wiki/Personal_Public_Service_Number */ @@ -432,12 +440,12 @@ if (preg_match($preg, $ppsn)) { //return (true); - return Validate_IE::check_mod23($ppsn); + return Validate_IE::checkMOD23($ppsn); } - $preg = "/^[0-9]{7}[A-Z][\ WTX]?$/"; - if (preg_match($preg, $ppsn)){ - return Validate_IE::check_mod23($ppsn); + $preg = "/^[0-9]{7}[A-Z][\ WTX]?$/"; + if (preg_match($preg, $ppsn)) { + return Validate_IE::checkMOD23($ppsn); } else { return false; } @@ -446,8 +454,12 @@ // {{{ public function vatNumber /** - * vatNumber + * Validate Irish VAT registration number. * + * @param string $vat vat number to validate. + * + * @access public + * * <code> * <?php * // Include the package @@ -463,8 +475,6 @@ * ?> * </code> * - * @access public - * @param string $vat vat number to validate. * @return bool Returns true on success, false otherwise * @link http://www.iecomputersystems.com/ordering/eu_vat_numbers.htm */ @@ -472,7 +482,8 @@ { // IE1234567X or IE1X34567X are valid (includes one or two letters // either the last or second + last). - return (preg_match('/^IE\d{7}[a-z]$/i', $vat) || preg_match('/^IE\d[a-z]\d{5}[a-z]$/i', $vat)); + return (preg_match('/^IE\d{7}[a-z]$/i', $vat) || + preg_match('/^IE\d[a-z]\d{5}[a-z]$/i', $vat)); } // }}} }
« previous php.pear.cvs (#47868) next »