Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Intl][5.0] Add parameters type-hints#32525
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| [1.123,'1.1',1,1], | ||
| [1.123,'1.12',2,2], | ||
| [1.123,'1.123', -1,0], | ||
| [1.123,'1','abc',0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
'abc' is passed as thevalue of thesetAttribute method here:
https://github.com/symfony/symfony/pull/32525/files#diff-2a5ae15ec68c5d666ce08a09d75690efR564
It's type-hinted atint so it throws a TypeError, however method's logic seems to handle case where it could be a string:
| * cast to Boolean and then to int again. This way, negative values are converted to 1 and string values to 0. |
I decided to keep the type hint asint and remove the use case of astring value
src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
tigitz commentedJul 13, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I decided at first to skip type-hints on methods throwing But since#32525 (review) was asked I've decided to be consistent through the rest of the codebase: |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Intl/Data/Generator/AbstractDataGenerator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| * @see https://en.wikipedia.org/wiki/ISO_4217#Active_codes | ||
| */ | ||
| publicfunctionformatCurrency($value,$currency) | ||
| publicfunctionformatCurrency(float$value,string$currency) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I‘m not sure if we should actually forcefloat here. Storing a decimal value as string is a valid pattern, especially when it comes to currency amounts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
AFAIU, thisNumberFormatter implementation is a sort of polyfill forIntl::NumberFormatter where$value is typed as float and generates the following error if passed as a string with strict types:Fatal error: Uncaught TypeError: NumberFormatter::formatCurrency() expects parameter 1 to be float, string given in
So question is, should we accept a wider range of type compared to the implementation it's trying to polyfill ?
Personally I would say no, I would expect this function to also throws a TypeError on string arg if the whole point of this class is to be as close as the "real" one.
I'll leave it type-hinted as a float for now, open to modification if team says otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
All right, thanks for checking.
fabpot commentedJul 27, 2019
@tigitz Can you have a look at the remaining comment here? Thank you. |
tigitz commentedJul 28, 2019
@fabpot yep will do tonight 👌 |
tigitz commentedAug 3, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Status: Needs Review @derrabus When you have time ;) |
Uh oh!
There was an error while loading.Please reload this page.
Tobion commentedAug 4, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It seems almost all classes in intl which are affected here are internal classes, e.g. for polyfill that are not meant to be extended. So we can add type hints in 4.4 to them because we don't need parameter variance from 7.2. What do you think@nicolas-grekas ? |
src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedAug 7, 2019
@Tobion I was about to answer yes, but |
Uh oh!
There was an error while loading.Please reload this page.
…y of internal class (Tobion)This PR was merged into the 3.4 branch.Discussion----------[Intl] fix nullable phpdocs and useless method visibility of internal class| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | no| New feature? | no <!-- please update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | yes <!-- please add some, will be required by reviewers -->| Fixed tickets || License | MIT| Doc PR |Fix stuff found in#32525Commits-------63b71b5 [Intl] fix nullable phpdocs and useless method visibility of internal class
Tobion left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Rebased
nicolas-grekas commentedAug 8, 2019
Thank you@tigitz. |
…, Tobion)This PR was squashed before being merged into the 5.0-dev branch (closes#32525).Discussion----------[Intl][5.0] Add parameters type-hints| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | yes <!-- please add some, will be required by reviewers -->| Fixed tickets | continuation of#24722 and checks for#32179| License | MIT| Doc PR | N/AThis PR replaces docblocks by type hints in the Intl component considering#32179. Some docblocks without valuable information got also removed.Commits-------ce79f4b [Intl][5.0] Add parameters type-hints
This PR replaces docblocks by type hints in the Intl component considering#32179. Some docblocks without valuable information got also removed.