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

Add Valid National Code Generator to fa_IR Person #1675

Conversation

thearsalan
Copy link
Contributor

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.

.gitignore Outdated
@@ -1,2 +1,3 @@
vendor
composer.lock
.idea/
Copy link
Owner

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

Copy link
Contributor Author

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 Show resolved Hide resolved
*/
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);
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did so.

$area = 0;

while (self::sumOfDigits($area) == 0) {
$area = mt_rand(0, 9) . mt_rand(0, 9) . mt_rand(0, 9);
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did so. Thank you.

/**
* @param $number
* @return int
* this helper method sums up the digits in a number
Copy link
Owner

Choose a reason for hiding this comment

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

useless comment, please remove

Copy link
Contributor Author

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.

@@ -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
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the reference link.

{
$area = 0;

while (self::sumOfDigits($area) == 0) {
Copy link
Owner

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'?

Copy link
Contributor Author

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.

* @param $area
* @param $core
* @return int
* this method uses the Iranian nationalCode validation algorithm to generate a valid 10-digit code
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did so.

@thearsalan thearsalan force-pushed the feature/add-valid-national-code-fa_IR branch 2 times, most recently from 7cdcf19 to facb0b5 Compare March 31, 2019 14:16
Copy link
Owner

@fzaninotto fzaninotto left a 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; // "کامکار"
Copy link
Owner

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

Copy link
Contributor Author

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 Show resolved Hide resolved
* This method uses the Iranian nationalCode validation algorithm to generate a valid 10-digit code
* @param $area
* @param $core
* @return int
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it.

@thearsalan thearsalan force-pushed the feature/add-valid-national-code-fa_IR branch from 2010b94 to cb01380 Compare April 1, 2019 21:13
@fzaninotto fzaninotto merged commit dc68be0 into fzaninotto:master Apr 1, 2019
@fzaninotto
Copy link
Owner

Thanks!

@thearsalan
Copy link
Contributor Author

thearsalan commented Apr 1, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants