-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add Valid National Code Generator to fa_IR Person #1675
Add Valid National Code Generator to fa_IR Person #1675
Conversation
.gitignore
Outdated
@@ -1,2 +1,3 @@ | |||
vendor | |||
composer.lock | |||
.idea/ |
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.
Please remove that, it should be in your user gitignore
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.
You got it. My bad!
src/Faker/Provider/fa_IR/Person.php
Outdated
*/ | ||
private static function createCoreCode() | ||
{ | ||
return mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9) . mt_rand(1, 9); |
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.
please use the numerify formatter
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.
Did so.
src/Faker/Provider/fa_IR/Person.php
Outdated
$area = 0; | ||
|
||
while (self::sumOfDigits($area) == 0) { | ||
$area = mt_rand(0, 9) . mt_rand(0, 9) . mt_rand(0, 9); |
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.
please use the numerify formatter
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.
Did so. Thank you.
src/Faker/Provider/fa_IR/Person.php
Outdated
/** | ||
* @param $number | ||
* @return int | ||
* this helper method sums up the digits in a 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.
useless comment, please remove
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.
You got it. Actually, since I updated the while loop which used this method, this method is now obsolete, so I omitted it.
src/Faker/Provider/fa_IR/Person.php
Outdated
@@ -134,4 +134,82 @@ class Person extends \Faker\Provider\Person | |||
|
|||
protected static $titleMale = array('آقای', 'استاد', 'دکتر', 'مهندس'); | |||
protected static $titleFemale = array('خانم', 'استاد', 'دکتر', 'مهندس'); | |||
|
|||
/** | |||
* this method returns a valid Iranian nationalCode |
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.
please add a link to an official specification of that code
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.
Added the reference link.
src/Faker/Provider/fa_IR/Person.php
Outdated
{ | ||
$area = 0; | ||
|
||
while (self::sumOfDigits($area) == 0) { |
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.
can't you do it faster by testing $area == '000'
?
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.
Yes, it is faster. Updated the loop.
src/Faker/Provider/fa_IR/Person.php
Outdated
* @param $area | ||
* @param $core | ||
* @return int | ||
* this method uses the Iranian nationalCode validation algorithm to generate a valid 10-digit code |
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.
please link to the specification algorithm. Also, please put the description as the first line in the phpDoc, not the last one
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.
Did so.
7cdcf19
to
facb0b5
Compare
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.
A few more changes before I can merge this PR
readme.md
Outdated
echo $faker->firstNameFemale; // "مارال" | ||
|
||
// Generates a random last name | ||
echo $faker->lastName; // "کامکار" |
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.
please don't document formatters that exist on all locales, only the ones that are specific to your locale
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.
You got it.
src/Faker/Provider/fa_IR/Person.php
Outdated
* This method uses the Iranian nationalCode validation algorithm to generate a valid 10-digit code | ||
* @param $area | ||
* @param $core | ||
* @return int |
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.
same, please put return annotatino last in the list
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.
Updated it.
2010b94
to
cb01380
Compare
Thanks! |
Awesome! Thank you, sir!
…On Tue, Apr 2, 2019 at 1:53 AM Francois Zaninotto ***@***.***> wrote:
Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1675 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALf1Nwxm5vw143s9mIN9JGYflgs2AuVjks5vcnjIgaJpZM4b3_Sz>
.
--
Best Regards,
Arsalan Yarveisi
Co-Founder and CEO at Drupz (https://www.drupz.ir)
Ph.D. Candidate in
IT Management, Univer
sity of Tehran
|
I have updated the fa_IR Person Provider so as to add a main method and some helpers in order to enable the developer to generate valid national codes for fake Iranian Person instances.