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

Improving pt_BR Providers #545

Merged
merged 18 commits into from
May 19, 2015

Conversation

igorsantos07
Copy link
Contributor

  • In overall, code extensibility was improved;
  • Added some Brazilian documents to the Person provider;
  • Phone generation was greatly improved, being able to differentiate between landline and cellphones + additional local rules for valid numbers.
  • added samples to the repository README

New version of #335, with CS and other fixes

Code extensibility was improved by changing private property to protected;
Additional methods to generate some Brazilian documents were included
PhoneNumber was rewritten to enable different phone rules in Brazil.
Now it generated area codes, landline and cellphone numbers, obeying
the rules for the new digit that was added in the last years (and
will still be added in the future). The formats are now local-only,
like the original PhoneNumber class.
- several CS fixes
- improved strategy for random selection of phone types
- improved default values for formatting
- not overwriting phoneNumber() signature anymore; a phoneNumberCleared() was added instead
- added changes on phoneNumber/phoneNumberCleared
- fixed typo
@@ -90,7 +90,7 @@ class Person extends \Faker\Provider\Person

Copy link
Owner

Choose a reason for hiding this comment

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

The file permissions have changed, please revert to 644.

@igorsantos07
Copy link
Contributor Author

It seems the Travis build failed because of composer issues, on PHP 7.

* @param bool $formatted If the number should have dots/slashes/dashes or not.
* @return string
*/
public function cnpj($formatted = true)
Copy link

Choose a reason for hiding this comment

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

CNPJ is a Company property, not Person.
Can you move it?

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'm not really sure if we need to create a whole new provider just to generate company documents. Even more if you consider that's a juridic person document, same as the CPF for a physical person.

Copy link

Choose a reason for hiding this comment

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

Here are the company provider.
https://github.com/fzaninotto/Faker/blob/master/src/Faker/Provider/pt_BR/Company.php

A juridic person is a company, how said on Wikipedia, CNPJ is an identification number to companies and legal entities. I think is more logical move this property to company provider.

Eg.
I, as a person, have a CPF
I, as a company, have a CNPJ

I don't know if it make sense for you. Please, tell me what you think about it.

- CNPJ is a company document, thus the move
- check digit function was properly named, and moved into a separate
  file, as it's used by both classes. Furthermore, as the check digit
  algorithm is particular to Brazil (it's a variation of mod11, with
  different maximum multipliers given the number length) it was not
  placed in Faker/Calculator.
- Brazilian RG generator was included, as originally request by
  @hussani and @ianrodrigues at fzaninotto#488 and fzaninotto#551
- Check digit PHPDoc was included, moving in validation links from
  CPF and CNPJ generators
@oliveiraev
Copy link
Contributor

I, particularly, disagree with an RG generator. RG doesn't follows any pattern across the states. While RG's in São Paulo matches \d{1,3}\.\d{3}\.\d{3}-[0-9x], RG's in Minas Gerais follow something near \d{4,}[A-Z] and no state provides any validator or algorithm checker to avoid generate real persons documents.

@igorsantos07
Copy link
Contributor Author

I guess there's no such a thing as an algorithm to avoid real documents
whatsoever.

Usually RG is accepted as plain text across systems. On top of that, it's
semantically better to have something like an RG method instead of a random
number generator.

If someone needs a specific state's version, one can simply PR an algorithm
flag :)
I should also add that the algorithm used covers SP and RJ needs, to say
the least.
On 1 Apr 2015 12:01, "Evandro Oliveira" notifications@github.com wrote:

I, particularly, disagree with an RG generator. RG doesn't follows any
pattern across the states. While RG's in São Paulo matches
\d{1,3}.\d{3}.\d{3}-[0-9x], RG's in Minas Gerais follow something near
\d{4,}[A-Z] and no state provides any validator or algorithm checker to
avoid generate real persons documents.


Reply to this email directly or view it on GitHub
#545 (comment).

@igorsantos07
Copy link
Contributor Author

Any news on this, @fzaninotto?

public function testRgFormatIsValid()
{
$rg = $this->faker->rg(false);
echo $rg."\n";
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

echo $rg."\n";
$this->assertRegExp('/\d{8}\d/', $rg);
$rg = $this->faker->rg(true);
echo $rg."\n";
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

@fzaninotto
Copy link
Owner

Good PR, I'll merge as soon as you fix the two minor debug statements.

@igorsantos07
Copy link
Contributor Author

Whoops! Fixed now.

@igorsantos07
Copy link
Contributor Author

@fzaninotto, stuff is fixed ;)

fzaninotto added a commit that referenced this pull request May 19, 2015
@fzaninotto fzaninotto merged commit 0ae75f0 into fzaninotto:master May 19, 2015
@fzaninotto
Copy link
Owner

Thanks!

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.

4 participants