robertogallea / laravel-codicefiscale

Codice fiscale validation for php/laravel
MIT License
42 stars 16 forks source link

Samples in README not working #43

Closed JBou closed 2 years ago

JBou commented 2 years ago

Detailed description

The code in the README on How to use the Utility CodiceFiscale class is outdated: in case of error, CodiceFiscale::parse() returns false, and you will find information about the error using CodiceFiscale::getError(), which returns one of the defined constants among the following:

In reality, in case of an error, the parse method is throwing an exception. You have to catch the exception to get the errorcode and the getError method in the CodiceFiscale utility class is useless, the value is never set.

Context

For me, the code used in the README seems much cleaner than catching an exception. And when first using the library, the samples in the README were not working.

Possible implementation

Can you somehow change it to make it work like in the README, or add a second method tryParse which doesn't throw an exception?

robertogallea commented 2 years ago

Making a breaking change for this issue is kind of problematic. I think it would be better to add a tryParse() (or similar) method. Would you mind making the PR yourself? Thanks!