From f7c80bec98d775c1ff6376ea0c3d40686c262178 Mon Sep 17 00:00:00 2001 From: toin0u Date: Sat, 10 Nov 2012 20:22:01 +0100 Subject: [PATCH] Updated: Danish provider & Readme --- readme.md | 37 ++++++++++++++++++++++++++++ src/Faker/Provider/da_DK/Address.php | 8 +++--- src/Faker/Provider/da_DK/Company.php | 25 ++++++++++++++++--- src/Faker/Provider/da_DK/Person.php | 15 +++++++++++ 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index efe782c7..b2935b9a 100644 --- a/readme.md +++ b/readme.md @@ -565,6 +565,43 @@ echo $faker->region; // "Saint-Pierre-et-Miquelon" ``` +### `Faker\Provider\da_DK\Person` + +```php +cpr; // "051280-2387" + +``` + +### `Faker\Provider\da_DK\Address` + +```php +kommune; // "Frederiksberg" + +// Generates a random region name +echo $faker->region; // "Region Sjælland" + +``` + +### `Faker\Provider\da_DK\Company` + +```php +cvr; // "32458723" + +// Generates a random P number +echo $faker->p; // "5398237590" + +``` + + ## License Faker is released under the MIT Licence. See the bundled LICENSE file for details. diff --git a/src/Faker/Provider/da_DK/Address.php b/src/Faker/Provider/da_DK/Address.php index fece8c40..1742875b 100644 --- a/src/Faker/Provider/da_DK/Address.php +++ b/src/Faker/Provider/da_DK/Address.php @@ -119,9 +119,9 @@ class Address extends \Faker\Provider\Address ); /** - * @var array Danish municipalities. + * @var array Danish municipalities, called 'kommuner' in danish. */ - protected static $municipalityNames = array( + protected static $kommuneNames = array( 'København','Frederiksberg','Ballerup','Brøndby','Dragør','Gentofte','Gladsaxe','Glostrup','Herlev', 'Albertslund','Hvidovre','Høje Taastrup','Lyngby-Taarbæk','Rødovre','Ishøj','Tårnby','Vallensbæk', 'Allerød','Fredensborg','Helsingør','Hillerød','Hørsholm','Rudersdal','Egedal','Frederikssund','Greve', @@ -265,9 +265,9 @@ class Address extends \Faker\Provider\Address * * @return string */ - public static function municipality() + public static function kommune() { - return static::randomElement(static::$municipalityNames); + return static::randomElement(static::$kommuneNames); } /** diff --git a/src/Faker/Provider/da_DK/Company.php b/src/Faker/Provider/da_DK/Company.php index 2f90cd76..b9f289cc 100644 --- a/src/Faker/Provider/da_DK/Company.php +++ b/src/Faker/Provider/da_DK/Company.php @@ -35,12 +35,21 @@ class Company extends \Faker\Provider\Company protected static $companySuffix = array('ApS', 'A/S', 'I/S', 'K/S'); /** - * @var string CVR format. + * @link http://cvr.dk/Site/Forms/CMS/DisplayPage.aspx?pageid=60 + * + * @var string CVR number format. */ - protected static $cvrFormat = "%#######"; + protected static $cvrFormat = '%#######'; /** - * Generates a cvr number (8 digits). + * @link http://cvr.dk/Site/Forms/CMS/DisplayPage.aspx?pageid=60 + * + * @var string P number (production number) format. + */ + protected static $pFormat = '%#########'; + + /** + * Generates a CVR number (8 digits). * * @return string */ @@ -48,4 +57,14 @@ class Company extends \Faker\Provider\Company { return static::numerify(static::$cvrFormat); } + + /** + * Generates a P entity number (10 digits). + * + * @return string + */ + public static function p() + { + return static::numerify(static::$pFormat); + } } diff --git a/src/Faker/Provider/da_DK/Person.php b/src/Faker/Provider/da_DK/Person.php index bd564965..69ef595e 100644 --- a/src/Faker/Provider/da_DK/Person.php +++ b/src/Faker/Provider/da_DK/Person.php @@ -165,4 +165,19 @@ class Person extends \Faker\Provider\Person { return static::randomElement(static::$middleName); } + + /** + * Randomly return a danish CPR number (Personnal identification number) format. + * + * @link http://cpr.dk/cpr/site.aspx?p=16 + * @link http://en.wikipedia.org/wiki/Personal_identification_number_%28Denmark%29 + * + * @return string + */ + public static function cpr() + { + $birthdate = new \DateTime('@' . mt_rand(0, time())); + + return sprintf('%s-%s', $birthdate->format('dmy'), static::numerify('%###')); + } }