-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add a swiss social security number (AVS13) generator #1533
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Please get back to us on the requested changes or provide feedback then we can take this further from there. Nice work!
src/Faker/Provider/fr_CH/Person.php
Outdated
* @return string A string of {@see $length} random digits | ||
* @throws \OutOfBoundsException | ||
*/ | ||
protected static function generateRandomDigits($length = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon this kind of method should go into Faker/Provider/Base
but you probably could get the same result using numberBetween
src/Faker/Provider/fr_CH/Person.php
Outdated
* @param string $digits | ||
* @return int | ||
*/ | ||
protected static function computeAvs13Checksum($digits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would probably fit better in the Faker/Calculator
namespace, instead of being buried in a localized provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide a separate test for this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. Would it be better to create an Ean13 utility class since it's using the same algorithm ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a Luhn (etc.) calculator class, that does sound like a good idea to group it like that.
src/Faker/Provider/fr_CH/Person.php
Outdated
* @see https://www.zas.admin.ch/zas/fr/home/partenaires-et-institutions-/navs13.html | ||
* @return string | ||
*/ | ||
public function navs13() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a static method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will update that.
public function testAvsNumber() | ||
{ | ||
$avs = $this->faker->navs13; | ||
$this->assertRegExp('/^756\.([0-9]{4})\.([0-9]{4})\.([0-9]{2})$/i', $avs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to do an assertion about the checksum here? Would that suffice to check the whole number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, a checksum verification should be enough to assert the number is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after a bit of thinking, I believe it's still pertinent to assert the format of the generated number since the format is part of the specification. Sure, the checksum would confirm that the number is a valid EAN-13 number but it could validate any EAN-13 that is NOT an AVS13 number.
Here a brief of the changes I've made :
|
Any updates regarding this PR ? |
Hi, any news about this great PR? |
Hi, @Ph0tonic, thanks for your comment. I was waiting for a validation on this PR but I completely forgot about it. @fzaninotto it would be much appreciated if you could take a look at it. |
Hi, |
Thanks for contributing! |
Hey,
This is a random generator for swiss social security numbers (AVS13). I've made sure the code is correct using
make sniff
and ran the tests against the new code. It should all be good. I've also added an entry in the readme.md file to document the new provider.Any feedback is welcome.
Regards.