From 000bee8b4eac4a54eeea7e27fc092dcb3b5e1d8f Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Sat, 15 Aug 2015 19:33:21 +0300 Subject: [PATCH 1/8] Lithuanian phone numbers --- src/Faker/Provider/lt_LT/PhoneNumber.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Faker/Provider/lt_LT/PhoneNumber.php diff --git a/src/Faker/Provider/lt_LT/PhoneNumber.php b/src/Faker/Provider/lt_LT/PhoneNumber.php new file mode 100644 index 0000000000..05f2bf4d70 --- /dev/null +++ b/src/Faker/Provider/lt_LT/PhoneNumber.php @@ -0,0 +1,17 @@ + Date: Sat, 15 Aug 2015 19:41:56 +0300 Subject: [PATCH 2/8] Lithuanian domain tlds and email username --- src/Faker/Provider/lt_LT/Internet.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/Faker/Provider/lt_LT/Internet.php diff --git a/src/Faker/Provider/lt_LT/Internet.php b/src/Faker/Provider/lt_LT/Internet.php new file mode 100644 index 0000000000..f562fa5f2c --- /dev/null +++ b/src/Faker/Provider/lt_LT/Internet.php @@ -0,0 +1,18 @@ + Date: Sat, 15 Aug 2015 19:47:51 +0300 Subject: [PATCH 3/8] Lithuanian Companies --- src/Faker/Provider/lt_LT/Company.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/Faker/Provider/lt_LT/Company.php diff --git a/src/Faker/Provider/lt_LT/Company.php b/src/Faker/Provider/lt_LT/Company.php new file mode 100644 index 0000000000..b11447393b --- /dev/null +++ b/src/Faker/Provider/lt_LT/Company.php @@ -0,0 +1,15 @@ + Date: Sat, 15 Aug 2015 20:07:38 +0300 Subject: [PATCH 4/8] Lithuanian address format --- src/Faker/Provider/lt_LT/Address.php | 127 +++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/Faker/Provider/lt_LT/Address.php diff --git a/src/Faker/Provider/lt_LT/Address.php b/src/Faker/Provider/lt_LT/Address.php new file mode 100644 index 0000000000..4056f66edf --- /dev/null +++ b/src/Faker/Provider/lt_LT/Address.php @@ -0,0 +1,127 @@ +generator->parse($format); + } + + public static function country() + { + return static::randomElement(static::$country); + } + + public static function postcode() + { + return static::toUpper(static::bothify(static::randomElement(static::$postcode))); + } + + public static function regionSuffix() + { + return static::randomElement(static::$regionSuffix); + } + + public static function region() + { + return static::randomElement(static::$region); + } + + public static function citySuffix() + { + return static::randomElement(static::$citySuffix); + } + + public function city() + { + return static::randomElement(static::$city); + } + + public static function streetSuffix() + { + return static::randomElement(static::$streetSuffix); + } + + public static function street() + { + return static::randomElement(static::$street); + } +} From 490ff9f5e50f23f1d54f5d7158af9afe3a62155e Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Sat, 15 Aug 2015 20:14:49 +0300 Subject: [PATCH 5/8] Lithuanian names and personal identification number --- src/Faker/Provider/lt_LT/Person.php | 351 ++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 src/Faker/Provider/lt_LT/Person.php diff --git a/src/Faker/Provider/lt_LT/Person.php b/src/Faker/Provider/lt_LT/Person.php new file mode 100644 index 0000000000..b1fbc98462 --- /dev/null +++ b/src/Faker/Provider/lt_LT/Person.php @@ -0,0 +1,351 @@ +bothify("########"); + } + + /** + * Return passport number + * @return string + * @example 12345678 + */ + public function passportNumber() + { + return $this->bothify("########"); + } + + /** + * National Personal Identity number (asmens kodas) + * @link https://en.wikipedia.org/wiki/National_identification_number#Lithuania + * @link https://lt.wikipedia.org/wiki/Asmens_kodas + * @param string [male|female] + * @param \DateTime $birthdate + * @param string $randomNumber three integers + * @return string on format XXXXXXXXXXX + */ + public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = null, $randomNumber = '') + { + if (!$birthdate) { + $birthdate = \Faker\Provider\DateTime::dateTimeThisCentury(); + } + + $genderNumber = ($gender == 'male') ? (int) 1 : (int) 0; + $firstNumber = (int) floor($birthdate->format('Y') / 100) * 2 - 34 - $genderNumber; + + $datePart = $birthdate->format('ymd'); + $randomDigits = (string) ( ! $randomNumber || strlen($randomNumber < 3)) ? static::numerify('###') : substr($randomNumber, 0, 3); + var_dump($randomDigits); + $partOfPerosnalCode = $firstNumber . $datePart . $randomDigits; + + $sum = self::calculateSum($partOfPerosnalCode, 1); + $liekana = $sum % 11; + + if ($liekana !== 10) { + $lastNumber = $liekana; + return $firstNumber . $datePart . $randomDigits . $lastNumber; + } + + $sum = self::calculateSum($partOfPerosnalCode, 2); + $liekana = (int) $sum % 11; + + $lastNumber = ($liekana !== 10) ? $liekana : 0; + return $firstNumber . $datePart . $randomDigits . $lastNumber; + } + + /** + * Calculate the sum of personal code + * @link https://en.wikipedia.org/wiki/National_identification_number#Lithuania + * @link https://lt.wikipedia.org/wiki/Asmens_kodas + * @param string $numbers + * @param int $time [1|2] + * @return int + */ + private static function calculateSum( $numbers, $time = 1) + { + if ($time == 1) { + $multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ]; + } else { + $multipliers = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3 ]; + } + + $sum = 0; + for ($i=1; $i <= 10; $i++) { + $sum += $numbers[$i-1] * $multipliers[$i-1]; + } + + return (int) $sum; + } +} From 80b3347d2a9b3b1a47a4e4a3e6799f98a27d5198 Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Sat, 15 Aug 2015 20:36:27 +0300 Subject: [PATCH 6/8] Fix PSR-2 issues --- src/Faker/Provider/lt_LT/Address.php | 8 ++++++-- src/Faker/Provider/lt_LT/Internet.php | 2 +- src/Faker/Provider/lt_LT/Person.php | 2 +- src/Faker/Provider/lt_LT/PhoneNumber.php | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Faker/Provider/lt_LT/Address.php b/src/Faker/Provider/lt_LT/Address.php index 4056f66edf..5f446408c1 100644 --- a/src/Faker/Provider/lt_LT/Address.php +++ b/src/Faker/Provider/lt_LT/Address.php @@ -11,8 +11,12 @@ class Address extends \Faker\Provider\Address 'g.', 'gatvė', 'prospektas', 'alėja', ); - protected static $buildingNumber = array('##'); protected static $postcode = array('LT-#####'); protected static - $country = array('Afganistanas', 'Airija', 'Alandų salos', 'Albanija', 'Alžyras', 'Amerikos Samoa', 'Andora', + protected static $buildingNumber = array('##'); + + protected static $postcode = array('LT-#####'); + + protected static $country = array( + 'Afganistanas', 'Airija', 'Alandų salos', 'Albanija', 'Alžyras', 'Amerikos Samoa', 'Andora', 'Angilija', 'Angola', 'Antarktis', 'Antigva ir Barbuda', 'Argentina', 'Armėnija', 'Aruba', 'Australija', 'Austrija', 'Azerbaidžanas', 'Bahamos', 'Bahreinas', 'Baltarusija', 'Bangladešas', 'Barbadosas', 'Belgija', 'Belizas', 'Beninas', 'Bermuda', 'Bisau Gvinėja', 'Bolivija', 'Bosnija ir Hercegovina', 'Botsvana', 'Bouvet sala', 'Brazilija', diff --git a/src/Faker/Provider/lt_LT/Internet.php b/src/Faker/Provider/lt_LT/Internet.php index f562fa5f2c..f98ccc4389 100644 --- a/src/Faker/Provider/lt_LT/Internet.php +++ b/src/Faker/Provider/lt_LT/Internet.php @@ -15,4 +15,4 @@ class Internet extends \Faker\Provider\Internet protected static $freeEmailDomain = array('gmail.com', 'yahoo.com', 'hotmail.com'); protected static $tld = array('com', 'com', 'net', 'org', 'lt', 'lt', 'lt', 'lt', 'lt'); -} \ No newline at end of file +} diff --git a/src/Faker/Provider/lt_LT/Person.php b/src/Faker/Provider/lt_LT/Person.php index b1fbc98462..21eb838698 100644 --- a/src/Faker/Provider/lt_LT/Person.php +++ b/src/Faker/Provider/lt_LT/Person.php @@ -333,7 +333,7 @@ public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = * @param int $time [1|2] * @return int */ - private static function calculateSum( $numbers, $time = 1) + private static function calculateSum($numbers, $time = 1) { if ($time == 1) { $multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ]; diff --git a/src/Faker/Provider/lt_LT/PhoneNumber.php b/src/Faker/Provider/lt_LT/PhoneNumber.php index 05f2bf4d70..752eb78b98 100644 --- a/src/Faker/Provider/lt_LT/PhoneNumber.php +++ b/src/Faker/Provider/lt_LT/PhoneNumber.php @@ -14,4 +14,4 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber '+370 46 ## ## ##', '(8 46) ## ## ##', ); -} \ No newline at end of file +} From dad36047eeb48f2c0e9501a7b3aed65406d0ad35 Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Sat, 15 Aug 2015 20:47:21 +0300 Subject: [PATCH 7/8] Remove short arrays syntax for PHP 5.3 --- src/Faker/Provider/lt_LT/Person.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Faker/Provider/lt_LT/Person.php b/src/Faker/Provider/lt_LT/Person.php index 21eb838698..933e99594e 100644 --- a/src/Faker/Provider/lt_LT/Person.php +++ b/src/Faker/Provider/lt_LT/Person.php @@ -336,9 +336,9 @@ public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = private static function calculateSum($numbers, $time = 1) { if ($time == 1) { - $multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ]; + $multipliers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ); } else { - $multipliers = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3 ]; + $multipliers = array(3, 4, 5, 6, 7, 8, 9, 1, 2, 3 ); } $sum = 0; From c57dc24b80b74f3ff2faf6714fc8fdccd14e4a90 Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Sat, 15 Aug 2015 20:50:09 +0300 Subject: [PATCH 8/8] Remove var_dump --- src/Faker/Provider/lt_LT/Person.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Faker/Provider/lt_LT/Person.php b/src/Faker/Provider/lt_LT/Person.php index 933e99594e..47b862bc16 100644 --- a/src/Faker/Provider/lt_LT/Person.php +++ b/src/Faker/Provider/lt_LT/Person.php @@ -307,7 +307,6 @@ public function personalIdentityNumber($gender = 'male', \DateTime $birthdate = $datePart = $birthdate->format('ymd'); $randomDigits = (string) ( ! $randomNumber || strlen($randomNumber < 3)) ? static::numerify('###') : substr($randomNumber, 0, 3); - var_dump($randomDigits); $partOfPerosnalCode = $firstNumber . $datePart . $randomDigits; $sum = self::calculateSum($partOfPerosnalCode, 1);