cvs: pear /Validate/Validate IN.php
| From: | Ken Guest | Date: | Wed, 12 Sep 2007 23:23:20 +0000 |
| Subject: | cvs: pear /Validate/Validate IN.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-48602@lists.php.net to get a copy of this message | ||
kguest Wed Sep 12 23:23:20 2007 UTC
Modified files:
/pear/Validate/Validate IN.php
Log:
Bug #12043 Ran phpcs on IN.php: found 45 errors and 13 warnings
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/IN.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Validate/Validate/IN.php diff -u pear/Validate/Validate/IN.php:1.3 pear/Validate/Validate/IN.php:1.4 --- pear/Validate/Validate/IN.php:1.3 Sat Aug 26 16:46:34 2006 +++ pear/Validate/Validate/IN.php Wed Sep 12 23:23:20 2007 @@ -1,31 +1,27 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Anant Narayanan | -// +----------------------------------------------------------------------+ -// | 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: Anant Narayanan <anant@php.net> | -// | Byron Adams <byron.adams54@gmail.com> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in India * - * @category Validate - * @package Validate_IN - * @author Anant Narayanan <anant@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Anant Narayanan - * @copyright (c) 2006 Byron Adams - * @version CVS: $Id: IN.php,v 1.3 2006/08/26 16:46:34 badams Exp $ - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * 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_IN + * @author Anant Narayanan <anant@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Anant Narayanan + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: IN.php,v 1.4 2007/09/12 23:23:20 kguest Exp $ + * @link http://pear.php.net/package/Validate_IN */ /** @@ -38,13 +34,14 @@ * - PAN/TAN Numbers * - Vehicle license plate Numbers * - * @category Validate - * @package Validate_IN - * @author Anant Narayanan <anant@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Anant Narayanan - * @copyright (c) 2006 Byron Adams - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @category Validate + * @package Validate_IN + * @author Anant Narayanan <anant@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Anant Narayanan + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @link http://pear.php.net/package/Validate_IN */ class Validate_IN @@ -53,11 +50,10 @@ * Validates an Indian Permanent Account Number (PAN) or * Tax deduction and collection Account Number (TAN). * + * @param string $number the PAN or TAN to be validated. + * * @access public - * @author Anant Narayanan - * - * @param string $number the PAN or TAN to be validated. - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function pan($number) { @@ -68,53 +64,52 @@ * Validates a state / union territory code and returns the full name of the * state / union territory code passed. * + * @param string $stateCode 2-letter region code + * * @access public * @see Validate_IN::region() - * @author Byron Adams - * @author Anant Narayanan * - * @param string $region 2-letter region code - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function stateCode($stateCode) { return Validate_IN::region($stateCode); } - + /** * Validates an Indian Vehicle's license plate number. * + * @param string $number the license plate number to validate. + * * @access public - * @author Anant Narayanan * - * @param string $number; the license plate number to validate. * @return bool true on success false otherwise */ function licensePlate($number) { - $regex = "/^[A-Z]{2}(\s|\-)?[0-9]{1,2}(\s|\-)?(S|C|R|V)?(\s|\-)?[A-Z]{0,2}(\s|\-)?\d{4}$/"; - + $regex = "/^[A-Z]{2}(\s|\-)?[0-9]{1,2}(\s|\-)?(S|C|R|V)?" + . "(\s|\-)?[A-Z]{0,2}(\s|\-)?\d{4}$/"; + if (Validate_IN::stateCode(substr($number, 0, 2))) { return preg_match($regex, $number); } return false; } - + /** * Validates an Indian Postal Code (ZIP code) * + * @param string $postalCode The ZIP code to validate + * * @access public - * @author Byron Adams - * @author Anant Narayanan * - * @param string $postalCode The ZIP code to validate - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function postalCode($postalCode) { $postalCode = preg_replace("/[^\d]/", "", $postalCode); - + return (strlen($postalCode) == 6 && $postalCode{0} != "0"); } @@ -123,96 +118,92 @@ * Validates an Indian Permanent Account Number (PAN) or * Tax deduction and collection Account Number (TAN). * + * @param string $ssn The PAN or TAN to be validated. + * * @access public - * @author Byron Adams * @see Validate_AU::pan() * - * @param string $ssn The PAN or TAN to be validated. - * @return bool true on success false otherwise + * @return bool true on success false otherwise * */ function ssn($ssn) { return Validate_IN::pan($ssn); } - + /** * Validates a state / union territory code and returns the full name of the * state / union territory code passed. * + * @param string $region 2-letter region code + * * @access public - * @author Byron Adams - * @author Anant Narayanan - * - * @param string $region 2-letter region code * @return bool true on success false otherwise */ function region($region) { static $states = array( - "AN", "AP", "AR", "AS", "BR", "CH", "CT", "DN", "DD", - "DL", "GA", "GJ", "HR", "HP", "JK", "JH", "KA", "KL", - "LD", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PY", - "PB", "RJ", "SK", "TN", "TR", "UL", "UP", "WB"); - - return in_array(strtoupper($region),$states); + "AN", "AP", "AR", "AS", "BR", "CH", "CT", "DN", "DD", + "DL", "GA", "GJ", "HR", "HP", "JK", "JH", "KA", "KL", + "LD", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PY", + "PB", "RJ", "SK", "TN", "TR", "UL", "UP", "WB"); + + return in_array(strtoupper($region), $states); } /** * Returns the full name of a state / union territory given a valid state * code. If state code is invalid or NULL, an array of all states is * returned. - * - * @access public - * @author Byron Adams - * @author Anant Narayanan * - * @param string $code 2-letter region code + * @param string $code 2-letter region code + * * @return bool true on success false otherwise * @return mixed Full name of state of code is valid, array of * all states if not. + * @access public */ - function getStateName($code = NULL) + function getStateName($code = null) { $code = strtoupper($code); - + static $states = array( - "AN" => "Andaman and Nicobar Islands", - "AP" => "Andhra Pradesh", - "AR" => "Arunachal Pradesh", - "AS" => "Assam", - "BR" => "Bihar", - "CH" => "Chandigarh", - "CT" => "Chattisgarh", - "DN" => "Dadra and Nagar Haveli", - "DD" => "Daman and Diu", - "DL" => "Delhi", - "GA" => "Goa", - "GJ" => "Gujarat", - "HR" => "Harayana", - "HP" => "Himachal Pradesh", - "JK" => "Jammu and Kashmir", - "JH" => "Jharkhand", - "KA" => "Karnataka", - "KL" => "Kerala", - "LD" => "Lakshwadeep", - "MP" => "Madhya Pradesh", - "MH" => "Maharashtra", - "MN" => "Manipur", - "ML" => "Meghalaya", - "MZ" => "Mizoram", - "NL" => "Nagaland", - "OR" => "Orissa", - "PY" => "Pondicherry", - "PB" => "Punjab", - "RJ" => "Rajasthan", - "SK" => "Sikkim", - "TN" => "Tamil Nadu", - "TR" => "Tripura", - "UL" => "Uttaranchal", - "UP" => "Uttar Pradesh", - "WB" => "West Bengal"); - + "AN" => "Andaman and Nicobar Islands", + "AP" => "Andhra Pradesh", + "AR" => "Arunachal Pradesh", + "AS" => "Assam", + "BR" => "Bihar", + "CH" => "Chandigarh", + "CT" => "Chattisgarh", + "DN" => "Dadra and Nagar Haveli", + "DD" => "Daman and Diu", + "DL" => "Delhi", + "GA" => "Goa", + "GJ" => "Gujarat", + "HR" => "Harayana", + "HP" => "Himachal Pradesh", + "JK" => "Jammu and Kashmir", + "JH" => "Jharkhand", + "KA" => "Karnataka", + "KL" => "Kerala", + "LD" => "Lakshwadeep", + "MP" => "Madhya Pradesh", + "MH" => "Maharashtra", + "MN" => "Manipur", + "ML" => "Meghalaya", + "MZ" => "Mizoram", + "NL" => "Nagaland", + "OR" => "Orissa", + "PY" => "Pondicherry", + "PB" => "Punjab", + "RJ" => "Rajasthan", + "SK" => "Sikkim", + "TN" => "Tamil Nadu", + "TR" => "Tripura", + "UL" => "Uttaranchal", + "UP" => "Uttar Pradesh", + "WB" => "West Bengal"); + if (array_key_exists($code, $states)) { return $states[$code]; } else { @@ -233,13 +224,11 @@ * where whitespaces, dashes and brackets may interchanged freely and 0/+ may * be added / skipped wherever possible. * - * @param string $number Phone number to validate (mobile or - * landline) - * - * @return bool True if number is valid, False otherwise + * @param string $number Phone number to validate (mobile or landline) * * @access public * @static + * @return bool True if number is valid, False otherwise */ function phoneNumber($number) { @@ -258,15 +247,15 @@ } // it's a landline, with or without area code - if (preg_match('/^\(?(0[1-9]{2,5}|\d{2,5})?(\s)?(\s|\)|\-)?(\s)?(2|3|5)\d{6,7}$/', - $number)) { + $reg = "/^\(?(0[1-9]{2,5}|\d{2,5})?(\s)?(\s|\)|\-)?(\s)?(2|3|5)\d{6,7}$/"; + if (preg_match($reg, $number)) { return true; } - + return false; } - - + + } ?>
http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/IN.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Validate/Validate/IN.php diff -u pear/Validate/Validate/IN.php:1.3 pear/Validate/Validate/IN.php:1.4 --- pear/Validate/Validate/IN.php:1.3 Sat Aug 26 16:46:34 2006 +++ pear/Validate/Validate/IN.php Wed Sep 12 23:23:20 2007 @@ -1,31 +1,27 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Anant Narayanan | -// +----------------------------------------------------------------------+ -// | 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: Anant Narayanan <anant@php.net> | -// | Byron Adams <byron.adams54@gmail.com> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in India * - * @category Validate - * @package Validate_IN - * @author Anant Narayanan <anant@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Anant Narayanan - * @copyright (c) 2006 Byron Adams - * @version CVS: $Id: IN.php,v 1.3 2006/08/26 16:46:34 badams Exp $ - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * 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_IN + * @author Anant Narayanan <anant@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Anant Narayanan + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: IN.php,v 1.4 2007/09/12 23:23:20 kguest Exp $ + * @link http://pear.php.net/package/Validate_IN */ /** @@ -38,13 +34,14 @@ * - PAN/TAN Numbers * - Vehicle license plate Numbers * - * @category Validate - * @package Validate_IN - * @author Anant Narayanan <anant@php.net> - * @author Byron Adams <byron.adams54@gmail.com> - * @copyright 1997-2005 Anant Narayanan - * @copyright (c) 2006 Byron Adams - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @category Validate + * @package Validate_IN + * @author Anant Narayanan <anant@php.net> + * @author Byron Adams <byron.adams54@gmail.com> + * @copyright 1997-2005 Anant Narayanan + * @copyright 2006 Byron Adams + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License + * @link http://pear.php.net/package/Validate_IN */ class Validate_IN @@ -53,11 +50,10 @@ * Validates an Indian Permanent Account Number (PAN) or * Tax deduction and collection Account Number (TAN). * + * @param string $number the PAN or TAN to be validated. + * * @access public - * @author Anant Narayanan - * - * @param string $number the PAN or TAN to be validated. - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function pan($number) { @@ -68,53 +64,52 @@ * Validates a state / union territory code and returns the full name of the * state / union territory code passed. * + * @param string $stateCode 2-letter region code + * * @access public * @see Validate_IN::region() - * @author Byron Adams - * @author Anant Narayanan * - * @param string $region 2-letter region code - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function stateCode($stateCode) { return Validate_IN::region($stateCode); } - + /** * Validates an Indian Vehicle's license plate number. * + * @param string $number the license plate number to validate. + * * @access public - * @author Anant Narayanan * - * @param string $number; the license plate number to validate. * @return bool true on success false otherwise */ function licensePlate($number) { - $regex = "/^[A-Z]{2}(\s|\-)?[0-9]{1,2}(\s|\-)?(S|C|R|V)?(\s|\-)?[A-Z]{0,2}(\s|\-)?\d{4}$/"; - + $regex = "/^[A-Z]{2}(\s|\-)?[0-9]{1,2}(\s|\-)?(S|C|R|V)?" + . "(\s|\-)?[A-Z]{0,2}(\s|\-)?\d{4}$/"; + if (Validate_IN::stateCode(substr($number, 0, 2))) { return preg_match($regex, $number); } return false; } - + /** * Validates an Indian Postal Code (ZIP code) * + * @param string $postalCode The ZIP code to validate + * * @access public - * @author Byron Adams - * @author Anant Narayanan * - * @param string $postalCode The ZIP code to validate - * @return bool true on success false otherwise + * @return bool true on success false otherwise */ function postalCode($postalCode) { $postalCode = preg_replace("/[^\d]/", "", $postalCode); - + return (strlen($postalCode) == 6 && $postalCode{0} != "0"); } @@ -123,96 +118,92 @@ * Validates an Indian Permanent Account Number (PAN) or * Tax deduction and collection Account Number (TAN). * + * @param string $ssn The PAN or TAN to be validated. + * * @access public - * @author Byron Adams * @see Validate_AU::pan() * - * @param string $ssn The PAN or TAN to be validated. - * @return bool true on success false otherwise + * @return bool true on success false otherwise * */ function ssn($ssn) { return Validate_IN::pan($ssn); } - + /** * Validates a state / union territory code and returns the full name of the * state / union territory code passed. * + * @param string $region 2-letter region code + * * @access public - * @author Byron Adams - * @author Anant Narayanan - * - * @param string $region 2-letter region code * @return bool true on success false otherwise */ function region($region) { static $states = array( - "AN", "AP", "AR", "AS", "BR", "CH", "CT", "DN", "DD", - "DL", "GA", "GJ", "HR", "HP", "JK", "JH", "KA", "KL", - "LD", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PY", - "PB", "RJ", "SK", "TN", "TR", "UL", "UP", "WB"); - - return in_array(strtoupper($region),$states); + "AN", "AP", "AR", "AS", "BR", "CH", "CT", "DN", "DD", + "DL", "GA", "GJ", "HR", "HP", "JK", "JH", "KA", "KL", + "LD", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PY", + "PB", "RJ", "SK", "TN", "TR", "UL", "UP", "WB"); + + return in_array(strtoupper($region), $states); } /** * Returns the full name of a state / union territory given a valid state * code. If state code is invalid or NULL, an array of all states is * returned. - * - * @access public - * @author Byron Adams - * @author Anant Narayanan * - * @param string $code 2-letter region code + * @param string $code 2-letter region code + * * @return bool true on success false otherwise * @return mixed Full name of state of code is valid, array of * all states if not. + * @access public */ - function getStateName($code = NULL) + function getStateName($code = null) { $code = strtoupper($code); - + static $states = array( - "AN" => "Andaman and Nicobar Islands", - "AP" => "Andhra Pradesh", - "AR" => "Arunachal Pradesh", - "AS" => "Assam", - "BR" => "Bihar", - "CH" => "Chandigarh", - "CT" => "Chattisgarh", - "DN" => "Dadra and Nagar Haveli", - "DD" => "Daman and Diu", - "DL" => "Delhi", - "GA" => "Goa", - "GJ" => "Gujarat", - "HR" => "Harayana", - "HP" => "Himachal Pradesh", - "JK" => "Jammu and Kashmir", - "JH" => "Jharkhand", - "KA" => "Karnataka", - "KL" => "Kerala", - "LD" => "Lakshwadeep", - "MP" => "Madhya Pradesh", - "MH" => "Maharashtra", - "MN" => "Manipur", - "ML" => "Meghalaya", - "MZ" => "Mizoram", - "NL" => "Nagaland", - "OR" => "Orissa", - "PY" => "Pondicherry", - "PB" => "Punjab", - "RJ" => "Rajasthan", - "SK" => "Sikkim", - "TN" => "Tamil Nadu", - "TR" => "Tripura", - "UL" => "Uttaranchal", - "UP" => "Uttar Pradesh", - "WB" => "West Bengal"); - + "AN" => "Andaman and Nicobar Islands", + "AP" => "Andhra Pradesh", + "AR" => "Arunachal Pradesh", + "AS" => "Assam", + "BR" => "Bihar", + "CH" => "Chandigarh", + "CT" => "Chattisgarh", + "DN" => "Dadra and Nagar Haveli", + "DD" => "Daman and Diu", + "DL" => "Delhi", + "GA" => "Goa", + "GJ" => "Gujarat", + "HR" => "Harayana", + "HP" => "Himachal Pradesh", + "JK" => "Jammu and Kashmir", + "JH" => "Jharkhand", + "KA" => "Karnataka", + "KL" => "Kerala", + "LD" => "Lakshwadeep", + "MP" => "Madhya Pradesh", + "MH" => "Maharashtra", + "MN" => "Manipur", + "ML" => "Meghalaya", + "MZ" => "Mizoram", + "NL" => "Nagaland", + "OR" => "Orissa", + "PY" => "Pondicherry", + "PB" => "Punjab", + "RJ" => "Rajasthan", + "SK" => "Sikkim", + "TN" => "Tamil Nadu", + "TR" => "Tripura", + "UL" => "Uttaranchal", + "UP" => "Uttar Pradesh", + "WB" => "West Bengal"); + if (array_key_exists($code, $states)) { return $states[$code]; } else { @@ -233,13 +224,11 @@ * where whitespaces, dashes and brackets may interchanged freely and 0/+ may * be added / skipped wherever possible. * - * @param string $number Phone number to validate (mobile or - * landline) - * - * @return bool True if number is valid, False otherwise + * @param string $number Phone number to validate (mobile or landline) * * @access public * @static + * @return bool True if number is valid, False otherwise */ function phoneNumber($number) { @@ -258,15 +247,15 @@ } // it's a landline, with or without area code - if (preg_match('/^\(?(0[1-9]{2,5}|\d{2,5})?(\s)?(\s|\)|\-)?(\s)?(2|3|5)\d{6,7}$/', - $number)) { + $reg = "/^\(?(0[1-9]{2,5}|\d{2,5})?(\s)?(\s|\)|\-)?(\s)?(2|3|5)\d{6,7}$/"; + if (preg_match($reg, $number)) { return true; } - + return false; } - - + + } ?>