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

Extract strings to constants #7078

Merged
merged 1 commit into from
Apr 17, 2021

Conversation

franmomu
Copy link
Member

@franmomu franmomu commented Apr 16, 2021

Subject

Some polishing, there are multiples places where these strings are used, this replaces the scalar strings by constants.

Since they seem related to Datagrid, I've created them in DatagridInterface. I've chosen KEY_ prefix, but any other name is welcome.

I am targeting this branch, because these changes are BC.

Changelog

### Added
- Added `DatagridInterface::SORT_ORDER` constant to use it instead of `_sort_order` string.
- Added `DatagridInterface::SORT_BY` constant to use it instead of `_sort_by` string.
- Added `DatagridInterface::PAGE` constant to use it instead of `_page` string.
- Added `DatagridInterface::PER_PAGE` constant to use it instead of `_per_page` string.

@franmomu franmomu added the minor label Apr 16, 2021
VincentLanglet
VincentLanglet previously approved these changes Apr 16, 2021
Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Seems nice

@VincentLanglet VincentLanglet requested a review from a team April 16, 2021 20:08
@jordisala1991
Copy link
Member

I think we are using as a key of an array is an implementation detail, what about just removing the prefix?

There are multiples places where these strings are used, this
replaces the scalar strings by constants.
$sortValues['_sort_order'] = 'ASC';
$sortValues['_sort_by'] = 'position';
$sortValues[DatagridInterface::PAGE] = 1;
$sortValues[DatagridInterface::SORT_ORDER] = 'ASC';
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about this, the phpdoc of the class says:

/**
 * Criteria for filtering Selectable collections.
 */

and the usage inside the doctrine organization: https://github.com/search?q=org%3Adoctrine+Criteria%3A%3ADESC&type=Code looks like it's only around the Criteria class.

@phansys phansys requested a review from core23 April 17, 2021 14:00
@jordisala1991 jordisala1991 merged commit 9735ad3 into sonata-project:3.x Apr 17, 2021
@jordisala1991
Copy link
Member

Thnk you @franmomu

@franmomu franmomu deleted the datagrid_constants branch April 17, 2021 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants