From cb3e371b7eaf347d59b7075b23a2baded7741e9c Mon Sep 17 00:00:00 2001 From: John Was Date: Mon, 16 Sep 2013 23:48:40 +0200 Subject: [PATCH 1/7] Polish addresses, personal identity number and pesel number generator --- src/Faker/Provider/pl_PL/Address.php | 99 ++++++++++++++++++++++++++++ src/Faker/Provider/pl_PL/Person.php | 53 +++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/Faker/Provider/pl_PL/Address.php diff --git a/src/Faker/Provider/pl_PL/Address.php b/src/Faker/Provider/pl_PL/Address.php new file mode 100644 index 00000000..5cab0a95 --- /dev/null +++ b/src/Faker/Provider/pl_PL/Address.php @@ -0,0 +1,99 @@ +format('Y'); + $year = (int)$birthdate->format('y'); + $month = $birthdate->format('m') + (((int)($fullYear/100) - 14) % 5) * 20; + $day = $birthdate->format('d'); + + $result = array((int)($year / 10), $year % 10, (int)($month / 10), $month % 10, (int)($day / 10), $day % 10); + + for ($i = 6; $i < $length; $i++) { + $result[$i] = static::randomDigit(); + } + if ($sex == "M") { + $b[$length - 1] |= 1; + } elseif ($sex == "F") { + $b[$length - 1] ^= 1; + } + $checksum = 0; + for ($i = 0; $i < $length; $i++) { + $checksum += $weights[$i] * $result[$i]; + } + $checksum = (10 - ($checksum % 10)) % 10; + $result[] = $checksum; + return implode('',$result); + } + + public static function personalIdentityNumber() + { + $range = str_split("ABCDEFGHIJKLMNPRSTUVWXYZ"); + $low = array("A", static::randomElement($range), static::randomElement($range)); + $high = array(static::randomDigit(), static::randomDigit(), static::randomDigit(), static::randomDigit(), static::randomDigit()); + $weights = array(7, 3, 1, 7, 3, 1, 7, 3); + $checksum = 0; + for ($i = 0; $i < count($low); $i++) { + $checksum += $weights[$i] * (ord($low[$i]) - 55); + } + for ($i = 0; $i < count($high); $i++) { + $checksum += $weights[$i+3] * $high[$i]; + } + $checksum %= 10; + return implode('',$low).$checksum.implode('',$high); + } } From 8119a9388eaf58e9cad6d3ef808dc508782302ae Mon Sep 17 00:00:00 2001 From: John Was Date: Tue, 17 Sep 2013 22:06:34 +0200 Subject: [PATCH 2/7] added comments and linked sources; use \Faker\Provider\DateTime::dateTimeThisCentury() for brithdate; added taxpayerIdentificationNumber() --- src/Faker/Provider/pl_PL/Address.php | 9 ++++++ src/Faker/Provider/pl_PL/Person.php | 43 +++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Faker/Provider/pl_PL/Address.php b/src/Faker/Provider/pl_PL/Address.php index 5cab0a95..9a945b78 100644 --- a/src/Faker/Provider/pl_PL/Address.php +++ b/src/Faker/Provider/pl_PL/Address.php @@ -13,6 +13,9 @@ class Address extends \Faker\Provider\Address protected static $buildingNumber = array('##A', '##', '##A/##', '##/##'); protected static $postcode = array('##-###'); + /** + * @var array full list of Polish voivodeship + */ protected static $state = array( 'dolnośląskie','kujawsko-pomorskie','lubelskie','lubuskie','łódzkie','małopolskie','mazowieckie','opolskie','podkarpackie', 'podlaskie','pomorskie','śląskie','świętokrzyskie','warmińsko-mazurskie','wielkopolskie','zachodniopomorskie' @@ -20,6 +23,9 @@ class Address extends \Faker\Provider\Address protected static $country = array( 'Polska', ); + /** + * @var array 250 Polish cities with biggest number of streets. Extracted from data issued by the official public postal service of Poland. @link http://www.poczta-polska.pl/ + */ protected static $city = array( 'Warszawa','Kraków','Łódź','Poznań','Wrocław','Gdańsk','Szczecin','Bydgoszcz','Lublin','Bielsko-Biała','Częstochowa','Katowice','Białystok','Gdynia','Radom', 'Rzeszów','Gliwice','Kielce','Opole','Rybnik','Sosnowiec','Zabrze','Ruda Śląska','Jaworzno','Olsztyn','Zielona Góra','Bytom','Koszalin','Dąbrowa Górnicza', @@ -39,6 +45,9 @@ class Address extends \Faker\Provider\Address 'Kętrzyn','Ostróda','Bochnia','Jelcz-Laskowice','Ząbki','Września','Bielawa','Nowy Targ','Giżycko','Dzierżoniów','Myszków','Marylka','Czechowice-Dziedzice','Łowicz','Łomianki','Świebodzice', 'Świebodzin','Lubojenka','Lubliniec','Świecie','Lubartów','Lidzbark Warmiński','Świdnik','Pisz','Szczytno','Świdwin','Kozienice','Brodnica','Kościerzyna','Braniewo','Koło' ); + /** + * @var array 549 most common Polish street names. Extracted from data issued by the official public postal service of Poland. @link http://www.poczta-polska.pl/ + */ protected static $street = array( 'Kościuszki Tadeusza','Mickiewicza Adama','Szkolna','Dworcowa','Kolejowa','Sienkiewicza Henryka','Rynek','Warszawska','Wojska Polskiego','Żeromskiego Stefana', 'Polna','1 Maja','Ogrodowa','Pocztowa','Grunwaldzka','Kopernika Mikołaja','Leśna','Lipowa','Słowackiego Juliusza','Parkowa','Kościelna','Jagiellońska','Słoneczna', diff --git a/src/Faker/Provider/pl_PL/Person.php b/src/Faker/Provider/pl_PL/Person.php index 9c88db89..e6727e7e 100644 --- a/src/Faker/Provider/pl_PL/Person.php +++ b/src/Faker/Provider/pl_PL/Person.php @@ -53,13 +53,17 @@ class Person extends \Faker\Provider\Person } /** + * PESEL - Universal Electronic System for Registration of the Population + * @link http://en.wikipedia.org/wiki/PESEL * @param DateTime $birthdate * @param string $sex M for male or F for female + * @return string 11 digit number, like 44051401358 */ public static function pesel($birthdate = null, $sex = null) { - if ($birthdate === null) - $birthdate = new \DateTime(date('Y-m-d',mt_rand(strtotime('1800-01-0'), time()))); + if ($birthdate === null) { + $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury(); + } $weights = array(1, 3, 7, 9, 1, 3, 7, 9, 1, 3); $length = count($weights); @@ -75,9 +79,9 @@ class Person extends \Faker\Provider\Person $result[$i] = static::randomDigit(); } if ($sex == "M") { - $b[$length - 1] |= 1; + $result[$length - 1] |= 1; } elseif ($sex == "F") { - $b[$length - 1] ^= 1; + $result[$length - 1] ^= 1; } $checksum = 0; for ($i = 0; $i < $length; $i++) { @@ -88,6 +92,11 @@ class Person extends \Faker\Provider\Person return implode('',$result); } + /** + * National Identity Card number + * @link http://en.wikipedia.org/wiki/Polish_National_Identity_Card + * @return string 3 letters and 6 digits, like ABA300000 + */ public static function personalIdentityNumber() { $range = str_split("ABCDEFGHIJKLMNPRSTUVWXYZ"); @@ -104,4 +113,30 @@ class Person extends \Faker\Provider\Person $checksum %= 10; return implode('',$low).$checksum.implode('',$high); } + + /** + * Taxpayer Identification Number (NIP in Polish) + * @link http://en.wikipedia.org/wiki/PESEL#Other_identifiers + * @link http://pl.wikipedia.org/wiki/NIP + * @return string 10 digit number + */ + public static function taxpayerIdentificationNumber() + { + $weights = array(6, 5, 7, 2, 3, 4, 5, 6, 7); + $result = array(); + do { + $result = array( + static::randomDigitNotNull(), static::randomDigitNotNull(), static::randomDigitNotNull(), + static::randomDigit(), static::randomDigit(), static::randomDigit(), + static::randomDigit(), static::randomDigit(), static::randomDigit(), + ); + $checksum = 0; + for ($i = 0; $i < count($result); $i++) { + $checksum += $weights[$i] * $result[$i]; + } + $checksum %= 11; + } while ($checksum == 10); + $result[] = $checksum; + return implode('', $result); + } } From bb7bd3355ac0523e5c0d2fdf1053e75f8e0594c5 Mon Sep 17 00:00:00 2001 From: John Was Date: Wed, 18 Sep 2013 00:35:58 +0200 Subject: [PATCH 3/7] Polish REGON number for companies, bank name and bank account number (IBAN) --- src/Faker/Provider/pl_PL/Company.php | 184 +++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 src/Faker/Provider/pl_PL/Company.php diff --git a/src/Faker/Provider/pl_PL/Company.php b/src/Faker/Provider/pl_PL/Company.php new file mode 100644 index 00000000..050424b7 --- /dev/null +++ b/src/Faker/Provider/pl_PL/Company.php @@ -0,0 +1,184 @@ + 'Aareal Bank Aktiengesellschaft (Spółka Akcyjna) - Oddział w Polsce', + '249' => 'Alior Bank SA', + '247' => 'Banco Espirito Santo de Investimento, S.A. Spółka Akcyjna Oddział w Polsce', + '238' => 'Banco Mais S.A. (SA) Oddział w Polsce', + '106' => 'Bank BPH SA', + '219' => 'Bank DnB NORD Polska SA', + '203' => 'Bank Gospodarki Żywnościowej SA', + '113' => 'Bank Gospodarstwa Krajowego', + '122' => 'Bank Handlowo - Kredytowy SA (w likwidacji 31.03.92)', + '103' => 'Bank Handlowy w Warszawie SA', + '116' => 'Bank Millennium SA', + '154' => 'Bank Ochrony Środowiska SA', + '260' => 'Bank of China (Luxembourg)S.A. Spółka Akcyjna Oddział w Polsce', + '221' => 'Bank of Tokyo-Mitsubishi UFJ (Polska) SA', + '132' => 'Bank Pocztowy SA', + '124' => 'Bank Polska Kasa Opieki SA', + '193' => 'BANK POLSKIEJ SPÓŁDZIELCZOŚCI SA', + '109' => 'Bank Zachodni WBK SA', + '224' => 'Banque PSA Finance SA Oddział w Polsce', + '160' => 'BNP PARIBAS BANK POLSKA SA', + '235' => 'BNP PARIBAS SA Oddział w Polsce', + '243' => 'BNP Paribas Securities Services SKAOddział w Polsce', + '229' => 'BPI Bank Polskich Inwestycji SA', + '215' => 'BRE Bank Hipoteczny SA', + '114' => 'BRE Bank SA', + '239' => 'CAIXABANK, S.A. (SPÓŁKA AKCYJNA)ODDZIAŁ W POLSCE', + '254' => 'Citibank Europe plc (Publiczna Spółka Akcyjna) Oddział w Polsce', + '194' => 'Credit Agricole Bank Polska SA', + '252' => 'CREDIT SUISSE (LUXEMBOURG) S.A. Spółka Akcyjna, Oddział w Polsce', + '236' => 'Danske Bank A/S SA Oddział w Polsce', + '191' => 'Deutsche Bank PBC SA', + '188' => 'Deutsche Bank Polska SA', + '174' => 'DZ BANK Polska SA', + '241' => 'Elavon Financial Services Limited (Spółka z ograniczoną odpowiedzialnością) Oddział w Polsce', + '147' => 'Euro Bank SA', + '265' => 'EUROCLEAR Bank SA/NV (Spółka Akcyjna) - Oddział w Polsce', + '207' => 'FCE Bank Polska SA', + '214' => 'Fiat Bank Polska SA', + '253' => 'FM Bank SA', + '248' => 'Getin Noble Bank SA', + '128' => 'HSBC Bank Polska SA', + '195' => 'Idea Bank SA', + '255' => 'Ikano Bank GmbH (Sp. z o.o.) Oddział w Polsce', + '262' => 'Industrial and Commercial Bank of China (Europe) S.A. (Spółka Akcyjna) Oddział w Polsce', + '105' => 'ING Bank Śląski SA', + '266' => 'Intesa Sanpaolo S.p.A. Spółka Akcyjna Oddział w Polsce', + '168' => 'INVEST - BANK SA', + '258' => 'J.P. Morgan Europe Limited Sp. z o.o. Oddział w Polsce', + '158' => 'Mercedes-Benz Bank Polska SA', + '130' => 'Meritum Bank ICB SA', + '101' => 'Narodowy Bank Polski', + '256' => 'Nordea Bank AB SA Oddział w Polsce', + '144' => 'NORDEA BANK POLSKA SA', + '232' => 'Nykredit Realkredit A/S SA - Oddział w Polsce', + '189' => 'Pekao Bank Hipoteczny SA', + '187' => 'Polski Bank Przedsiębiorczości SA', + '102' => 'Powszechna Kasa Oszczędności Bank Polski SA', + '200' => 'Rabobank Polska SA', + '175' => 'Raiffeisen Bank Polska SA', + '167' => 'RBS Bank (Polska) SA', + '264' => 'RCI Banque Spółka Akcyjna Oddział w Polsce', + '212' => 'Santander Consumer Bank SA', + '263' => 'Saxo Bank A/S Spółka Akcyjna Oddział w Polsce', + '161' => 'SGB-Bank SA', + '237' => 'Skandinaviska Enskilda Banken AB (SA) - Oddział w Polsce', + '184' => 'Societe Generale SA Oddział w Polsce', + '225' => 'Svenska Handelsbanken AB SA Oddział w Polsce', + '227' => 'Sygma Banque Societe Anonyme (SA) Oddział w Polsce', + '216' => 'Toyota Bank Polska SA', + '257' => 'UBS Limited (spółka z ograniczoną odpowiedzialnością) Oddział w Polsce', + '261' => 'Vanquis Bank Limited (spółka z ograniczoną odpowiedzialnością) Oddział w Polsce', + '213' => 'VOLKSWAGEN BANK POLSKA SA', + ); + /** + * Register of the National Economy + * @link http://pl.wikipedia.org/wiki/REGON + * @return 9 digit number + */ + public static function regon() + { + $weights = Array(8, 9, 2, 3, 4, 5, 6, 7); + $regionNumber = static::numberBetween(0, 49) * 2 + 1; + $result = array((int)($regionNumber / 10), $regionNumber % 10); + for ($i = 2; $i < count($weights); $i++) { + $result[$i] = static::randomDigit(); + } + $checksum = 0; + for ($i = 0; $i < count($result); $i++) { + $checksum += $weights[$i] * $result[$i]; + } + $checksum %= 11; + if ($checksum == 10) { + $checksum = 0; + } + $result[] = $checksum; + return implode('', $result); + } + + /** + * Register of the National Economy, local entity number + * @link http://pl.wikipedia.org/wiki/REGON + * @return 14 digit number + */ + public static function regonLocal() + { + $weights = array(2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8); + $result = str_split(static::regon()); + for ($i = count($result); $i < count($weights); $i++) { + $result[$i] = static::randomDigit(); + } + $checksum = 0; + for ($i = 0; $i < count($result); $i++) { + $checksum += $weights[$i] * $result[$i]; + } + $checksum %= 11; + if ($checksum == 10) { + $checksum = 0; + } + $result[] = $checksum; + return implode('', $result); + } + + /** + * @example 'Euro Bank SA' + */ + public static function bank() + { + return static::randomElement(static::$banks); + } + + /** + * International Bank Account Number (IBAN) in format: + * PLkk bbbs sssx cccc cccc cccc cccc + * 28 characters, where: + * b = National bank code + * s = Branch code + * x = National check digit + * c = Account number, + * @link http://en.wikipedia.org/wiki/International_Bank_Account_Number + * @param string $prefix for generating bank account number of a specific bank + * @param integer $digitsNumber total length without country code and 2 check digits + * @param string $countryCode ISO 3166-1 alpha-2 country code + * @return string + */ + public static function bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') + { + $countryCode = strtoupper($countryCode); + $result = $prefix; + $digitsNumber -= strlen($prefix); + for ($i = 0; $i < $digitsNumber; $i++) { + $result .= static::randomDigit(); + } + if ($countryCode == "PL" && strlen($result) > 8) { + $checksum = 0; + $weights = array(7, 1, 3, 9, 7, 1, 3); + for ($i = 0; $i < 7; $i++) { + $checksum += $weights[$i] * (int)$result[$i]; + } + $checksum = $checksum % 10; + $result = substr($result, 0, 7) . $checksum . substr($result, 8); + } + $countryNumber = 100 * (ord($countryCode[0])-55) + (ord($countryCode[1])-55); + $tempResult = $result . $countryNumber . '00'; + // perform MOD97-10 checksum calculation + $checksum = (int)$tempResult[0]; + for ($i = 1; $i < strlen($tempResult); $i++) { + $checksum = (10 * $checksum + (int)$tempResult[$i]) % 97; + } + $checksum = 98 - $checksum; + if ($checksum < 10) + $checksum = '0'.$checksum; + return $countryCode . $checksum . $result; + } +} From 645956dbc9832e871cf6cf02670f566792397679 Mon Sep 17 00:00:00 2001 From: John Was Date: Wed, 18 Sep 2013 22:00:35 +0200 Subject: [PATCH 4/7] copied Company.bankAccountNumber method to base Company class; updated readme with an example --- readme.md | 1 + src/Faker/Provider/Company.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/readme.md b/readme.md index 36391ea8..480b44b6 100644 --- a/readme.md +++ b/readme.md @@ -96,6 +96,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle bs // 'e-enable robust architectures' company // 'Bogan-Treutel' companySuffix // 'and Sons' + bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') // 'PL08032566519460083829368443' ### `Faker\Provider\Lorem` diff --git a/src/Faker/Provider/Company.php b/src/Faker/Provider/Company.php index 208d9ce5..7a456808 100644 --- a/src/Faker/Provider/Company.php +++ b/src/Faker/Provider/Company.php @@ -27,4 +27,33 @@ class Company extends \Faker\Provider\Base { return static::randomElement(static::$companySuffix); } + + /** + * International Bank Account Number (IBAN) + * @link http://en.wikipedia.org/wiki/International_Bank_Account_Number + * @param string $prefix for generating bank account number of a specific bank + * @param integer $digitsNumber total length without country code and 2 check digits + * @param string $countryCode ISO 3166-1 alpha-2 country code + * @return string + */ + public static function bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') + { + $countryCode = strtoupper($countryCode); + $result = $prefix; + $digitsNumber -= strlen($prefix); + for ($i = 0; $i < $digitsNumber; $i++) { + $result .= static::randomDigit(); + } + $countryNumber = 100 * (ord($countryCode[0])-55) + (ord($countryCode[1])-55); + $tempResult = $result . $countryNumber . '00'; + // perform MOD97-10 checksum calculation + $checksum = (int)$tempResult[0]; + for ($i = 1; $i < strlen($tempResult); $i++) { + $checksum = (10 * $checksum + (int)$tempResult[$i]) % 97; + } + $checksum = 98 - $checksum; + if ($checksum < 10) + $checksum = '0'.$checksum; + return $countryCode . $checksum . $result; + } } From e182c98c0334d320bb3771e8d25b1b85486a7071 Mon Sep 17 00:00:00 2001 From: John Was Date: Thu, 19 Sep 2013 18:08:05 +0200 Subject: [PATCH 5/7] regon in Company --- src/Faker/Provider/pl_PL/Company.php | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Faker/Provider/pl_PL/Company.php diff --git a/src/Faker/Provider/pl_PL/Company.php b/src/Faker/Provider/pl_PL/Company.php new file mode 100644 index 00000000..0bb94edc --- /dev/null +++ b/src/Faker/Provider/pl_PL/Company.php @@ -0,0 +1,55 @@ + Date: Thu, 19 Sep 2013 18:10:24 +0200 Subject: [PATCH 6/7] reverted previous commit --- readme.md | 1 - src/Faker/Provider/Company.php | 59 ---------------------------------- 2 files changed, 60 deletions(-) delete mode 100644 src/Faker/Provider/Company.php diff --git a/readme.md b/readme.md index 480b44b6..36391ea8 100644 --- a/readme.md +++ b/readme.md @@ -96,7 +96,6 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle bs // 'e-enable robust architectures' company // 'Bogan-Treutel' companySuffix // 'and Sons' - bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') // 'PL08032566519460083829368443' ### `Faker\Provider\Lorem` diff --git a/src/Faker/Provider/Company.php b/src/Faker/Provider/Company.php deleted file mode 100644 index 7a456808..00000000 --- a/src/Faker/Provider/Company.php +++ /dev/null @@ -1,59 +0,0 @@ -generator->parse($format); - } - - /** - * @example 'Ltd' - */ - public static function companySuffix() - { - return static::randomElement(static::$companySuffix); - } - - /** - * International Bank Account Number (IBAN) - * @link http://en.wikipedia.org/wiki/International_Bank_Account_Number - * @param string $prefix for generating bank account number of a specific bank - * @param integer $digitsNumber total length without country code and 2 check digits - * @param string $countryCode ISO 3166-1 alpha-2 country code - * @return string - */ - public static function bankAccountNumber($prefix = '', $digitsNumber = 24, $countryCode = 'PL') - { - $countryCode = strtoupper($countryCode); - $result = $prefix; - $digitsNumber -= strlen($prefix); - for ($i = 0; $i < $digitsNumber; $i++) { - $result .= static::randomDigit(); - } - $countryNumber = 100 * (ord($countryCode[0])-55) + (ord($countryCode[1])-55); - $tempResult = $result . $countryNumber . '00'; - // perform MOD97-10 checksum calculation - $checksum = (int)$tempResult[0]; - for ($i = 1; $i < strlen($tempResult); $i++) { - $checksum = (10 * $checksum + (int)$tempResult[$i]) % 97; - } - $checksum = 98 - $checksum; - if ($checksum < 10) - $checksum = '0'.$checksum; - return $countryCode . $checksum . $result; - } -} From d0de1b6825ee8abb2a0b6d756cbb69bcc1ef2484 Mon Sep 17 00:00:00 2001 From: John Was Date: Thu, 19 Sep 2013 18:12:28 +0200 Subject: [PATCH 7/7] restored Company.php deleted by mistake --- src/Faker/Provider/Company.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Faker/Provider/Company.php diff --git a/src/Faker/Provider/Company.php b/src/Faker/Provider/Company.php new file mode 100644 index 00000000..208d9ce5 --- /dev/null +++ b/src/Faker/Provider/Company.php @@ -0,0 +1,30 @@ +generator->parse($format); + } + + /** + * @example 'Ltd' + */ + public static function companySuffix() + { + return static::randomElement(static::$companySuffix); + } +}