-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Finder] added "use natural sort" option #27024
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
Conversation
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.
Almost good, thank you.
* @return $this | ||
* | ||
* @see SortableIterator | ||
*/ | ||
public function sortByName() | ||
public function sortByName($naturalOrdering = false) |
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.
for BC concerns, this should be handled using func_num_args()/func_get_arg(0)
(adding a new argument breaks child classes).
The signature should then be written as sortByName(/* bool $useNaturalOrdering = false */)
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.
Most of the times "sort" and "order" are interchangeable. However, given that our method is called sortByName
, we use a $this->sort
property and PHP calls this "natsort" for "natural sort" ... could we please rename $useNaturalOrdering
to $useNaturalSort
?
@@ -6,6 +6,7 @@ CHANGELOG | |||
|
|||
* deprecated `Symfony\Component\Finder\Iterator\FilterIterator` | |||
* added Finder::hasResults() method to check if any results were found | |||
* added $naturalOrdering option to Finder::sortByName() method |
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.
$useNaturalOrdering
looks more explicit to me
@@ -397,13 +397,17 @@ public function sort(\Closure $closure) | |||
* | |||
* This can be slow as all the matching files and directories must be retrieved for comparison. | |||
* | |||
* @param bool $naturalOrdering Whether to use natural ordering or not |
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.
@param bool $useNaturalOrdering Whether to use natural ordering or not, disabled by default
{ | ||
$this->sort = Iterator\SortableIterator::SORT_BY_NAME; | ||
$this->sort = $naturalOrdering |
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.
our CS favors single lines, please adjust
New features should target master (aka 4.2)! |
@nicolas-grekas So I have to add a message to |
yes please |
{ | ||
$this->sort = Iterator\SortableIterator::SORT_BY_NAME; | ||
$useNaturalSort = 1 === func_num_args() && true === func_get_arg(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.
I'd be a bit more lax here: 0 < func_num_args() && func_get_arg(0)
Does anybody have any idea why AppVeyor build has been failed? |
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.
(failure unrelated)
Thank you @vyshkant. |
This PR was merged into the 4.2-dev branch. Discussion ---------- [Finder] added "use natural sort" option | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26930 | License | MIT | Doc PR | symfony/symfony-docs#9671 Added `$useNaturalSort` optional argument to `Finder::sortByName()` method. If it is specified and equals to `true`, ["natural sort order" algorithm](https://en.wikipedia.org/wiki/Natural_sort_order) will be applied, which means that `strnatcmp` function will be used instead of `strcmp` (see #26930 for details). Commits ------- e697c7d [Finder] added "use natural sort" option
Added
$useNaturalSort
optional argument toFinder::sortByName()
method. If it is specified and equals totrue
, "natural sort order" algorithm will be applied, which means thatstrnatcmp
function will be used instead ofstrcmp
(see #26930 for details).