Add hint to formatter, so a hint can be provided if postcode is invalid#19
Add hint to formatter, so a hint can be provided if postcode is invalid#19lisotton wants to merge 1 commit intobrick:masterfrom
Conversation
aeaf601 to
79bf981
Compare
79bf981 to
3d57d0d
Compare
BenMorel
left a comment
There was a problem hiding this comment.
Hi @lisotton, this is an excellent suggestion, thank you for taking the time to implement it!
Something that caught my eye is that CountryPostcodeFormatter::hint() is a fixed message that is only ever used to enrich the exception after we detect that a postcode is not right (and therefore have more information about the violation). Why not make CountryPostcodeFormatter::format() throw the exception, adding a custom hint based on the error?
This would fix elegantly I think, what I pointed out on the AF formatter: depending on the input, we could have either of these errors:
-
Postcodes consist of 4 digits, without separator.
-
Province code (first 2 digits) must be between 10 and 43.
What do you think?
| { | ||
| public function hint(): string | ||
| { | ||
| return 'Postcodes consist of 4 digits, without separator.'; |
There was a problem hiding this comment.
To be really useful, we would need to mention the 10-43 province code as well.
|
@BenMorel I totally agree with your suggestion, but it took me already A LOT OF TIME to go through all the 182 classes, if we to go each class and each condition, it will be muuuuuch more time. |
|
I understand. I may find some time to help, if we can split the work! |
I think it will be a great addition to add a method to extract a helpful text from the formatter, so if the library is used in some application to validate the postcode, the hint can be used to provide why the provided postcode is invalid.