Skip to content
Browse files

Split out Validate_PL

  • Loading branch information...
1 parent 11b84d2 commit 590554d14ce66154fd730f5069f469a593f20ce0 @CloCkWeRX CloCkWeRX committed
Showing with 0 additions and 379 deletions.
  1. +0 −212 Validate/PL.php
  2. +0 −88 package_PL.xml
  3. +0 −79 tests/validate_PL.phpt
View
212 Validate/PL.php
@@ -1,212 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Specific validation methods for data used in Poland
- *
- * 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$
- * @link http://pear.php.net/package/Validate_PL
- */
-
-/**
-* Requires base class Validate
-*/
-require_once 'Validate.php';
-
-/**
- * Data validation class for Poland
- *
- * This class provides methods to validate:
- * - NIP (Polish tax identification number)
- * - Bank account number
- * - 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
- */
-class Validate_PL
-{
- /**
- * Validates NIP (Polish tax identification number)
- *
- * Sprawdza NIP (Numer Identyfikacji Podatkowej)
- * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html
- *
- * @param string $nip 9-digit number to validate
- *
- * @return bool
- */
- function nip($nip)
- {
- static $weights_nip = array(6,5,7,2,3,4,5,6,7);
-
- // remove any dashes, spaces, returns, tabs or slashes
- $nip = str_replace(array('-','/',' ',"\t","\n"), '', $nip);
-
- // check if this is a 10-digit number
- if (!is_numeric($nip) || strlen($nip) != 10) {
- return false;
- }
-
- // check control sum
- return Validate::_checkControlNumber($nip, $weights_nip, 11);
- }
-
- /**
- * Validates bank number (Polish banks)
- *
- * @param string $number 8-digit number to validate
- *
- * @return bool
- */
- function bankBranch($number)
- {
- static $weights_bank_branch = array(7,1,3,9,7,11,3);
-
- // remove any dashes, spaces, returns, tabs or slashes
- $number = str_replace(array('-','/',' ',"\t","\n"), '', $number);
-
- // check if this is a 8-digit number
- if (!is_numeric($number) || strlen($number) != 8) {
- return false;
- }
-
- // check control sum
- return Validate::_checkControlNumber($number, $weights_bank_branch, 10);
- }
-
- /**
- * Validates PESEL (Polish human identification number)
- *
- * Sprawdza PESEL (Powszechny Elektroniczny System Ewidencji Ludnoci)
- * http://www.mswia.gov.pl/crp_pesel.html
- * 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
- * (either 'female' or 'male' string) extracted from pesel
- *
- * @return bool
- */
- function pesel($pesel, &$birth)
- {
- static $weights_pesel = array(1,3,7,9,1,3,7,9,1,3);
-
- $birth = array(false,false);
-
- // remove any dashes, spaces, returns, tabs or slashes
- $pesel = str_replace(array('-','/',' ',"\t","\n"), '', $pesel);
-
- // check if this is a 11-digit number
- if (!is_numeric($pesel) || strlen($pesel) != 11) {
- return false;
- }
-
- if (Validate::_checkControlNumber($pesel,
- $weights_pesel,
- 10,
- 10) === false) {
- return false;
- }
-
- // now extract birth date from PESEL number
- $vy = substr($pesel, 0, 2);
- $vm = substr($pesel, 2, 2);
- $vd = substr($pesel, 4, 2);
-
- // decode century
- if ($vm < 20) {
- $vy += 1900;
- } elseif ($vm < 40) {
- $vy += 2000;
- } elseif ($vm < 60) {
- $vy += 2100;
- } elseif ($vm < 80) {
- $vy += 2200;
- } else {
- $vy += 1800;
- }
- $vm %= 20;
- $birth[0] = "$vy-$vm-$vd";
-
- // decode gender
- $gender = substr($pesel, 9, 1) % 2;
- $birth[1] = ($gender % 2 == 0) ? 'female' : 'male';
-
- return true;
- }
-
- /**
- * Validates REGON (Polish statistical national economy register)
- *
- * Sprawdza REGON (Rejestr Gospodarki Narodowej)
- * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html
- *
- * @param string $regon 9- or 14- digit number to validate
- *
- * @return bool
- */
- function regon($regon)
- {
- return Validate_PL::region($regon);
- }
-
- /**
- * Validates REGON (Polish statistical national economy register)
- *
- * Sprawdza REGON (Rejestr Gospodarki Narodowej)
- * http://chemeng.p.lodz.pl/zylla/ut/nip-rego.html
- *
- * @param string $regon 9- or 14- digit number to validate
- *
- * @return bool
- */
- function region($regon)
- {
- static $weights_regon = array(8,9,2,3,4,5,6,7);
- static $weights_regon_local = array(2,4,8,5,0,9,7,3,6,1,2,4,8);
-
- // remove any dashes, spaces, returns, tabs or slashes
- $regon = str_replace(array('-','/',' ',"\t","\n"), '', $regon);
-
- // check if this is a 9- or 14-digit number
- if (!is_numeric($regon) || (strlen($regon) != 9 && strlen($regon) != 14)) {
- return false;
- }
-
- // first check first 9 digits
- if (Validate::_checkControlNumber($regon, $weights_regon, 11) === false) {
- return false;
- }
-
- // check wide number if there are 14 digits
- if (strlen($regon) == 14) {
- // check 14 digits
- return Validate::_checkControlNumber($regon, $weights_regon_local, 11);
- }
-
- return true;
- }
-}
-?>
View
88 package_PL.xml
@@ -1,88 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.7.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
- <name>Validate_PL</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for PL</summary>
- <description>Package containes locale validation for PL such as:
- * NIP
- * Bank Numbers
- * PESEL
- * REGON</description>
- <lead>
- <name>Piotr Klaban</name>
- <user>makler</user>
- <email>makler@man.torun.pl</email>
- <active>no</active>
- </lead>
- <date>2009-03-23</date>
- <time>00:22:28</time>
- <version>
- <release>0.5.2</release>
- <api>0.5.2</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>QA release.
-Updated to package 2.0
-Fixed Bug #8565 - php doc element wrong
-Fixed Bug #12152 - PHPCS</notes>
- <contents>
- <dir baseinstalldir="/" name="/">
- <file baseinstalldir="/" md5sum="d023cd123bfb471b02fd07e006b321f7" name="tests/validate_PL.phpt" role="test" />
- <file baseinstalldir="/" md5sum="feef85f149ec2969c9b237d67194e23f" name="Validate/PL.php" role="php" />
- <file baseinstalldir="/" md5sum="7073f9a84fa6da71e7a505a777dda302" name="LICENSE" role="doc" />
- <file baseinstalldir="/" md5sum="fc4e390223df731fb3036031778c4978" name="package_PL.xml" role="data" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.4.9</min>
- </php>
- <pearinstaller>
- <min>1.6.0</min>
- </pearinstaller>
- <package>
- <name>Validate</name>
- <channel>pear.php.net</channel>
- <min>0.5.0</min>
- </package>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.5.0</release>
- <api>0.5.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2005-05-20</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>- Split from Validate into independent package
-- CS fixes
-- renamed bank_branch to bankBranch</notes>
- </release>
- <release>
- <version>
- <release>0.5.2</release>
- <api>0.5.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2009-03-23</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
- <notes>Updated to package 2.0
-Fixed Bug #8565 - php doc element wrong
-Fixed Bug #12152 - PHPCS</notes>
- </release>
- </changelog>
-</package>
View
79 tests/validate_PL.phpt
@@ -1,79 +0,0 @@
---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

0 comments on commit 590554d

Please sign in to comment.
Something went wrong with that request. Please try again.