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

use Luhn to calculate ar_SA id numbers. #875

Merged
merged 11 commits into from
Oct 7, 2016

Conversation

FooBarQuaxx
Copy link
Contributor

No description provided.

public static function companyIdNumber()
{
do {
$number = static::numerify('700#######');
Copy link
Owner

Choose a reason for hiding this comment

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

nah, you can do better than try until it's valid!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this is exactly what is done on the Person provider for the same locale, but I will look for something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Luhn::computeCheckDigit() will give you the correct last digit.

Copy link
Owner

Choose a reason for hiding this comment

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

Then the Person provider is wrong, too, and you can update it while you're touching Luhns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I did on commit 757750f.

Copy link
Owner

Choose a reason for hiding this comment

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

It doesn't appear in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to sound stupid, but I see the changes on the last commit on this PR.

class Utils
{
// ripped unashamedly from https://github.com/grahamking/darkcoding-credit-card/blob/master/gencc.php
public static function generateLuhnNumber($prefix, $length)
Copy link
Owner

Choose a reason for hiding this comment

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

You already have everything in Faker\Calculator\Luhn. No need to reimplement it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it good enough now?


class Utils
{
public static function generateLuhnNumber($prefix, $length)
Copy link
Owner

Choose a reason for hiding this comment

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

this would be better placed in Faker\Calculator\Luhn

@FooBarQuaxx
Copy link
Contributor Author

Anything new about this pull request?

}

$pattern = $prefix . str_repeat('#', $length - strlen($prefix) - 1);
$partialValue = BaseProvider::numerify($pattern);
Copy link
Owner

Choose a reason for hiding this comment

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

you should pass the partialValue as parameter to this method, to separate the responsibilities: Luhn calculation (this class), random generation (Company.php)

@FooBarQuaxx
Copy link
Contributor Author

I have made the changes as I understand how they should be done. Please check.

@fzaninotto fzaninotto merged commit 39b867c into fzaninotto:master Oct 7, 2016
@fzaninotto
Copy link
Owner

Excellent, thanks for your contribution!

@FooBarQuaxx
Copy link
Contributor Author

Thank you too for help me through it.

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.

3 participants