Skip to content

[Finder] Case insensitive file sort #46126

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
Jul 22, 2022

Conversation

hmoreau
Copy link
Contributor

@hmoreau hmoreau commented Apr 20, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#16735

Add a second argument $useCaseInsensitive to sortByName() method to select between case sensitive and case insensitive sort.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@hmoreau hmoreau force-pushed the CASE_INSENSITIVE_FILE_LIST branch 2 times, most recently from 4b9ad93 to 5b30852 Compare April 20, 2022 19:28
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Thanks for this very complete PR with tests and docs.

I think we can improve the interface.

@@ -433,9 +433,14 @@ public function sort(\Closure $closure): static
*
* @see SortableIterator
*/
public function sortByName(bool $useNaturalSort = false): static
public function sortByName(bool $useNaturalSort = false, bool $useCaseInsensitive = false): static
Copy link
Member

@GromNaN GromNaN Apr 20, 2022

Choose a reason for hiding this comment

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

A list of Boolean arguments is not an expressive method signature. Alternatively, I propose that we allow the sort flag to be passed as argument; but I'm not sure our backward compatibility policy allows to modify the type of the 1st argument from bool to bool|int.

Instead, we can add the method sortByNameCaseInsensitive(bool $useNaturalSort = false) (name to be discussed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comments.
I will work on a dedicated sort function and correct the changelog.
Is this method name good enough ? sortByNameCaseInsensitive(bool $useNaturalSort = false) It seems a bit long but it is self explanatory.
How about sortByCaseName(bool $useNaturalSort = false) which is closer to the php functions strcasecmp and strnatcasecmp ?

Copy link
Member

Choose a reason for hiding this comment

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

3rd alternative, the Finder::sort() accepts a closure, but could also accept a value from a dedicated Enum.

@symfony/mergers I'm not sure if we can add a 2nd allowed type to an existing argument. From \Closure $arg to MyEnum|\Closure $arg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Meanwhile I have moved the code to sortByCaseName(bool $useNaturalSort = false)

@nicolas-grekas nicolas-grekas modified the milestones: 6.1, 6.2 Apr 21, 2022
public function sortByCaseName(bool $useNaturalSort = false): static
{
$this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL_CASE_INSENSITIVE :
Iterator\SortableIterator::SORT_BY_NAME_CASE_INSENSITIVE;
Copy link
Member

Choose a reason for hiding this comment

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

this should stay on the same line

@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
Copy link
Member

Choose a reason for hiding this comment

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

this will likely be 6.2 as we are past the feature freeze for 6.1

@hmoreau hmoreau force-pushed the CASE_INSENSITIVE_FILE_LIST branch from 82d04f6 to 2f26995 Compare April 27, 2022 08:48
@hmoreau
Copy link
Contributor Author

hmoreau commented Apr 27, 2022

I made the change to sortByCaseInsensitiveName

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Can you rebase on current 6.2 to eliminate the merge commits (we don't merge PRs with merge commits)?

@fabpot fabpot force-pushed the CASE_INSENSITIVE_FILE_LIST branch from ee5661b to 7fdbb61 Compare July 22, 2022 12:41
@fabpot
Copy link
Member

fabpot commented Jul 22, 2022

Thank you @hmoreau.

@fabpot fabpot merged commit 25c8806 into symfony:6.2 Jul 22, 2022
@hmoreau
Copy link
Contributor Author

hmoreau commented Jul 22, 2022

Thank you @fabpot , @GromNaN , @javiereguiluz , @nicolas-grekas and @stof

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Aug 9, 2022
This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

[Finder] Add case insensitive sort

Add a new sortByCaseInsensitiveName() method to have case insensitive sorting results.
Like the sortByName(), pass true as its argument to use PHP's case insensitive natural sort order algorithm instead.

Related to symfony/symfony#46126 PR
Replace #16735 PR

Commits
-------

df9281f [Finder] Add case insensitive sort
@fabpot fabpot mentioned this pull request Oct 24, 2022
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.

7 participants