cvs: pear /Validate/Validate PL.php /Validate/tests validate_PL.phpt

From: Date: Sun, 30 Sep 2007 16:31:46 +0000
Subject: cvs: pear /Validate/Validate PL.php /Validate/tests validate_PL.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48732@lists.php.net to get a copy of this message
kguest Sun Sep 30 16:31:46 2007 UTC Added files: /pear/Validate/tests validate_PL.phpt Modified files: /pear/Validate/Validate PL.php Log: Bug #12152 coding standard errors plus no unit testing

http://cvs.php.net/viewvc.cgi/pear/Validate/Validate/PL.php?r1=1.12&r2=1.13&diff_format=u Index: pear/Validate/Validate/PL.php diff -u pear/Validate/Validate/PL.php:1.12 pear/Validate/Validate/PL.php:1.13 --- pear/Validate/Validate/PL.php:1.12 Sat Apr 7 13:05:50 2007 +++ pear/Validate/Validate/PL.php Sun Sep 30 16:31:46 2007 @@ -1,30 +1,25 @@ <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2005 Piotr Klaban | -// +----------------------------------------------------------------------+ -// | 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> | -// +----------------------------------------------------------------------+ -// /** * Specific validation methods for data used in Poland * - * @category Validate - * @package Validate_PL - * @author Piotr Klaban <makler@man.torun.pl> - * @copyright 1997-2005 Piotr Klaban - * @license http://www.opensource.org/licenses/bsd-license.php new BSD - * @version CVS: $Id: PL.php,v 1.12 2007/04/07 13:05:50 toggg Exp $ - * @link http://pear.php.net/package/Validate_PL + * 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_PL + * @author Piotr Klaban <makler@man.torun.pl> + * @copyright 1997-2005 Piotr Klaban + * @license http://www.opensource.org/licenses/bsd-license.php new BSD + * @version CVS: $Id: PL.php,v 1.13 2007/09/30 16:31:46 kguest Exp $ + * @link http://pear.php.net/package/Validate_PL */ /** @@ -41,13 +36,13 @@ * - PESEL (Polish human identification number) * - REGON (Polish statistical national economy register) * - * @category Validate - * @package Validate_PL - * @author Piotr Klaban <makler@man.torun.pl> - * @copyright 1997-2005 Piotr Klaban - * @license http://www.opensource.org/licenses/bsd-license.php new BSD - * @version Release: @package_version@ - * @link http://pear.php.net/package/Validate_PL + * @category Validate + * @package Validate_PL + * @author Piotr Klaban <makler@man.torun.pl> + * @copyright 1997-2005 Piotr Klaban + * @license http://www.opensource.org/licenses/bsd-license.php new BSD + * @version Release: @package_version@ + * @link http://pear.php.net/package/Validate_PL */ class Validate_PL { @@ -58,8 +53,8 @@ * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html * * @param string $nip 9-digit number to validate - * @returns bool - * @author Piotr Klaban <makler@man.torun.pl> + * + * @return bool */ function nip($nip) { @@ -81,8 +76,8 @@ * Validates bank number (Polish banks) * * @param string $number 8-digit number to validate - * @returns bool - * @author Piotr Klaban <makler@man.torun.pl> + * + * @return bool */ function bankBranch($number) { @@ -108,11 +103,11 @@ * NOTE: some people can have the same PESEL, and some can have * PESEL with wrong numbers in place of birth date. * - * @param string $pesel 11-digit number to validate - * @param array $birth reference to array - returns birth date and sex + * @param string $pesel 11-digit number to validate + * @param array &$birth reference to array - returns birth date and sex * (either 'female' or 'male' string) extracted from pesel - * @returns bool - * @author Piotr Klaban <makler@man.torun.pl> + * + * @return bool */ function pesel($pesel, &$birth) { @@ -128,7 +123,10 @@ return false; } - if (Validate::_checkControlNumber($pesel, $weights_pesel, 10, 10) === false) { + if (Validate::_checkControlNumber($pesel, + $weights_pesel, + 10, + 10) === false) { return false; } @@ -149,11 +147,11 @@ } else { $vy += 1800; } - $vm %= 20; + $vm %= 20; $birth[0] = "$vy-$vm-$vd"; // decode gender - $gender = substr($pesel,9,1) % 2; + $gender = substr($pesel, 9, 1) % 2; $birth[1] = ($gender % 2 == 0) ? 'female' : 'male'; return true; @@ -165,13 +163,13 @@ * Sprawdza REGON (Rejestr Gospodarki Narodowej) * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html * - * @param string $nip 9- or 14- digit number to validate - * @returns bool - * @author Piotr Klaban <makler@man.torun.pl> + * @param string $regon 9- or 14- digit number to validate + * + * @return bool */ function regon($regon) { - return Validate_PL::region($regon) + return Validate_PL::region($regon); } /** @@ -180,9 +178,9 @@ * Sprawdza REGON (Rejestr Gospodarki Narodowej) * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html * - * @param string $nip 9- or 14- digit number to validate - * @returns bool - * @author Piotr Klaban <makler@man.torun.pl> + * @param string $regon 9- or 14- digit number to validate + * + * @return bool */ function region($regon) { @@ -199,8 +197,8 @@ // first check first 9 digits if (Validate::_checkControlNumber($regon, $weights_regon, 11) === false) { - return false; - } + return false; + } // check wide number if there are 14 digits if (strlen($regon) == 14) { http://cvs.php.net/viewvc.cgi/pear/Validate/tests/validate_PL.phpt?view=markup&rev=1.1 Index: pear/Validate/tests/validate_PL.phpt +++ pear/Validate/tests/validate_PL.phpt --TEST-- validate_PL.phpt: Unit tests for Validation of Polish data. --FILE-- <?php $noYes = array('KO', 'OK'); $symbol = array('!X!', ' V '); include (dirname(__FILE__).'/validate_functions.inc'); if (is_file(dirname(__FILE__) . '/../Validate/PL.php')) { require_once dirname(__FILE__) . '/../Validate/PL.php'; } else { require 'Validate/PL.php'; } $validate = new Validate_PL; echo "Test Validate_PL\n"; echo "****************\n"; $nips = array ("7680002466","3385035171",); $regons = array("590096454", "590096455","002188077"); $pesels = array("40121008916","60052219867","33090901995","49110603787", "14665303253","42176454020","30261330924","18659635322"); $banks = array("94332544", "94332557", "94332560", "94332573", "94332586", "94332537", "94332538", "94332539", "94332540", "94332541"); echo "\nTest NIP\n"; foreach($nips as $nip) { printf("%s: %s\n", $nip, $noYes[$validate->nip($nip)]); } echo "\nTest REGON\n"; foreach($regons as $regon) { printf("%s: %s\n", $regon, $noYes[$validate->regon($regon)]); } echo "\nTest PESEL\n"; foreach($pesels as $pesel) { printf("%s: %s\n", $pesel, $noYes[$validate->pesel($pesel,$dn)]); } echo "\nTest Bank Branch\n"; foreach($banks as $bank) { printf("%s: %s\n", $bank, $noYes[$validate->bankBranch($bank,$dn)]); } exit(0); ?> --EXPECT-- Test Validate_PL **************** Test NIP 7680002466: OK 3385035171: KO Test REGON 590096454: OK 590096455: KO 002188077: OK Test PESEL 40121008916: OK 60052219867: OK 33090901995: OK 49110603787: OK 14665303253: OK 42176454020: KO 30261330924: KO 18659635322: KO Test Bank Branch 94332544: OK 94332557: OK 94332560: OK 94332573: OK 94332586: OK 94332537: KO 94332538: KO 94332539: KO 94332540: KO 94332541: KO
« previous php.pear.cvs (#48732) next »