8000 [Translator] Default value for 'sort' option in translation:update should be 'asc' by versgui · Pull Request #35486 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translator] Default value for 'sort' option in translation:update should be 'asc' #35486

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

Merged
merged 1 commit into from
Jan 30, 2020

Conversation

versgui
Copy link
@versgui versgui commented Jan 27, 2020
Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

The value for 'sort' option for bin/console translation:update --sort is optional, but no default value is defined. So the list isn't sorted if no value is explicitly defined.
This MR brings a default value "asc" if no value is defined, so the list is correctly sorted.

Copy link
Member
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you for this PR.
I dont see where you set the default value. Am I missing something?


return 1;
if ($input->hasOption('sort')) {
if ($sort = $input->getOption('sort')) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this ever be false?

Copy link
Author
@versgui versgui Jan 27, 2020

Choose a reason for hiding this comment

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

getOption() returns null if no value has been defined.

Line 296: if the sort option has been defined, even if it has no value.
Lines 297-304: if a value has been defined, check that it's valid
Line 307: if the option has been explicitly set to 'desc', makes an rsort()
Line 398: we do a sort() in all other cases (including if there's no value defined)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not defining the default value on the option definition instead of dealing with null and only allow asc and desc as strings and no empty value?

Copy link
Author
@versgui versgui Jan 27, 2020

Choose a reason for hiding this comment

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

I'm ok with this technicaly, but it would change the default behavior, where --sort=asc would be applied even if the --sort option is not specified. I didn't get into this because the goal is just to fix a bug, and I don't know if the default order responds to any particular logic.
There are actually three possible states: no sorting, asc and desc.

Copy link
Member

Choose a reason for hiding this comment

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

I would also set ASC as the default value of the option instead of allowing null which does not mean anything.

@versgui versgui changed the title Default value for 'sort' option in translation:update should be 'asc' [Translator] Default value for 'sort' option in translation:update should be 'asc' Jan 27, 2020

return 1;
if ($input->hasOption('sort')) {
if ($sort = $input->getOption('sort')) {
Copy link
Member

Choose a reason for hiding this comment

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

I would also set ASC as the default value of the option instead of allowing null which does not mean anything.

@versgui
Copy link
Author
versgui commented Jan 30, 2020

I made the modification: the command now returns the list with "sort=asc" by default.

Copy link
Member
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you.

Looking at if ($sort = $input->getOption('sort')), it is fine to keep the if statement. If someone calls with --sort=, we will be safe.

@fabpot fabpot force-pushed the translation_update_cmd_sort branch from 0b6a58c to fdb13c8 Compare January 30, 2020 16:24
@fabpot
Copy link
Member
fabpot commented Jan 30, 2020

Thank you @versgui.

fabpot added a commit that referenced this pull request Jan 30, 2020
…n:update should be 'asc' (versgui)

This PR was squashed before being merged into the 4.4 branch (closes #35486).

Discussion
----------

[Translator] Default value for 'sort' option in translation:update should be 'asc'

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

The value for 'sort' option for `bin/console translation:update --sort` is optional, but no default value is defined. So the list isn't sorted if no value is explicitly defined.
This MR brings a default value "asc" if no value is defined, so the list is correctly sorted.

Commits
-------

fdb13c8 [Translator] Default value for 'sort' option in translation:update should be 'asc'
@fabpot fabpot merged commit fdb13c8 into symfony:4.4 Jan 30, 2020
This was referenced Jan 31, 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.

5 participants
0