Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Added idNumber for nl_NL #1283

Merged
merged 7 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,14 @@ echo $faker->vat; // "NL123456789B01" - Dutch Value Added Tax number
echo $faker->btw; // "NL123456789B01" - Dutch Value Added Tax number (alias)
```

### `Faker\Provider\nl_NL\Person`

```php
<?php

echo $faker->idNumber; // "111222333" - Dutch Personal identificatin number (BSN)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo identificatin => identification

```

### `Faker\Provider\no_NO\Payment`

```php
Expand Down
33 changes: 33 additions & 0 deletions src/Faker/Provider/nl_NL/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,37 @@ public static function prefix()
{
return static::randomElement(static::$prefix);
}

/**
* @link https://nl.wikipedia.org/wiki/Burgerservicenummer#11-proef
*
* @return string
*/
public function idNumber()
{
$return = '';
$nr = array();
$nr[] = 0;
while (count($nr) < 8) {
$nr[] = static::randomDigit();
}
$nr[] = mt_rand(0, 6);
if ($nr[7] == 0 && $nr[8] == 0) {
$nr[7] = 0;
}

$bsn = (9 * $nr[8]) + (8 * $nr[7]) + (7 * $nr[6]) + (6 * $nr[5]) + (5 * $nr[4]) + (4 * $nr[3]) + (3 * $nr[2]) + (2 * $nr[1]);
$nr[0] = floor($bsn - floor($bsn / 11) * 11);
if ($nr[0] > 9) {
if ($nr[1] > 0) {
$nr[0] = 8;
$nr[1]--;
} else {
$nr[0] = 1;
$nr[1]++;

}
}
return implode('', array_reverse($nr));
}
}
32 changes: 32 additions & 0 deletions test/Faker/Provider/nl_NL/PersonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Faker\Test\Provider\nl_NL;

use Faker\Generator;
use Faker\Provider\nl_NL\Person;

class PersonTest extends \PHPUnit_Framework_TestCase
{
private $faker;

public function setUp()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$this->faker = $faker;
}

public function testGenerateValidIdNumber()
{
$idNumber = $this->faker->idNumber();
$this->assertEquals(9, strlen($idNumber));


$sum = -1 * $idNumber % 10;
for ($multiplier = 2; $idNumber > 0; $multiplier++) {
$val = ($idNumber /= 10) % 10;
$sum += $multiplier * $val;
}
$this->assertTrue($sum != 0 && $sum % 11 == 0);
}
}