Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generated zipcode patterns #38

Merged
merged 6 commits into from
May 18, 2015
Merged

Conversation

barryvdh
Copy link
Contributor

@barryvdh barryvdh commented May 8, 2015

Use auto-generated sources from http://i18napis.appspot.com with more countries available.

Deprecated the validateNetherlands($zipcode) calls in favor of the validate($zipcode, 'nl') so they could be removed some time (Or you would need to add methods for each country?)

This doesn't change the tests (and haven't run the tests yet).
Test could perhaps be modified to verify the examples from zipex in the data, but that wouldn't be needed if the source already tested those.

Easier to maintain, more available.
@barryvdh barryvdh mentioned this pull request May 8, 2015
*
* @return bool
* @deprecated use validate($zipcode, 'US')
Copy link
Contributor

Choose a reason for hiding this comment

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

Please specify since version is deprecated (1.1 ? 1.2 ? See with @ronanguilloux) and use trigger_error on the method to advice developers like this:

trigger_error('The '.__METHOD__.' method is deprecated since version 1.2 and will be removed in 2.0. You should use the validate($zipcode, $country) method instead.', E_USER_DEPRECATED);

See also with @ronanguilloux for which version we should remove deprecated method.

Copy link
Owner

Choose a reason for hiding this comment

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

Nice improvement, thank you @barryvdh.

OK for @soullivaneuh proposal: could you please add this E_USER_DEPRECATED error trigger to the @deprecated blocks (as in use in Symfony2 codebase by example)

As proposed, 1.2 starts the deprecation, and 2.0 will remove this.

trigger_error('The '.__METHOD__.' method is deprecated since version 1.2 and will be removed in 2.0. You should use the validate($zipcode, $country) method instead.', E_USER_DEPRECATED);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay but this will also trigger on validate($zipcode, 'Spain') so I tweaked the messages to include the correct code. Also fixed the tests.

And some frameworks turn those errors into Exceptions, so not sure how cool that is for everyone, but I changed it.

@soullivaneuh
Copy link
Contributor

Very good improvement, I like this! 👍

Is the database source up to date?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.42%) to 88.01% when pulling 9bdc90d on barryvdh:patch-2 into 058c428 on ronanguilloux:master.

@barryvdh
Copy link
Contributor Author

barryvdh commented May 8, 2015

Not sure, they reference it here: http://unicode.org/cldr/trac/browser/trunk/common/supplemental/postalCodeData.xml

That was from data from Google from 2009, the appspot api data is also from Google I think, so probably newer or the same.

All tests seem to pass except 0123AA, which should indeed fail. But that would probably be easier to just fix in the generated patterns.

But if there is a newer/better source (I couldn't find any so quickly), we could use that.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.42%) to 88.01% when pulling eb5f5c8 on barryvdh:patch-2 into 058c428 on ronanguilloux:master.

@soullivaneuh
Copy link
Contributor

Should be at least a good start. We can indeed maintain it manually later.

Code seems to be less covered according to coveralls, can you please take a look?

Check Exception is thrown and that validateNetherlands() etc are still callable.
@barryvdh
Copy link
Contributor Author

barryvdh commented May 8, 2015

Yeah the validateUS() wasn't called again. Added tests for directly calling those classes (which could perhaps be deprecated?) and also checked for the Exception, which didn't appear to be there already.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.26%) to 88.7% when pulling 77f6a2b on barryvdh:patch-2 into 058c428 on ronanguilloux:master.

@soullivaneuh
Copy link
Contributor

Added tests for directly calling those classes (which could perhaps be deprecated?)

I think it should be until this method could be used.

Let @ronanguilloux decide about it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.26%) to 88.7% when pulling 74b03ad on barryvdh:patch-2 into 058c428 on ronanguilloux:master.

@ronanguilloux ronanguilloux added this to the 1.2 milestone May 18, 2015
}

/**
* testUSZipCode
Copy link
Owner

Choose a reason for hiding this comment

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

This sould be testZipCodeCountryMethod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.86%) to 86.58% when pulling 044ceea on barryvdh:patch-2 into cd3cdc5 on ronanguilloux:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.86%) to 86.58% when pulling 044ceea on barryvdh:patch-2 into cd3cdc5 on ronanguilloux:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.16%) to 88.59% when pulling 0aafa53 on barryvdh:patch-2 into cd3cdc5 on ronanguilloux:master.

@barryvdh
Copy link
Contributor Author

I've also tested for the deprecated errors. Not sure if there is a prettier way..

ronanguilloux added a commit that referenced this pull request May 18, 2015
Use generated zipcode patterns
@ronanguilloux ronanguilloux merged commit b43ca68 into ronanguilloux:master May 18, 2015
@ronanguilloux
Copy link
Owner

Thanks

@barryvdh barryvdh deleted the patch-2 branch May 18, 2015 09:08
MaximeLC2 pushed a commit to Vigicorp/IsoCodes that referenced this pull request Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants