Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 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
nicolas-grekas 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.
Almost good, thank you.
| * @see SortableIterator | ||
| */ | ||
| publicfunctionsortByName() | ||
| publicfunctionsortByName($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 usingfunc_num_args()/func_get_arg(0) (adding a new argument breaks child classes).
The signature should then be written assortByName(/* bool $useNaturalOrdering = false */)
javiereguiluzApr 24, 2018 • 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.
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 calledsortByName, we use a$this->sort property and PHP calls this "natsort" for "natural sort" ... could we please rename$useNaturalOrdering to$useNaturalSort ?
| * 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
| * | ||
| * 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
| publicfunctionsortByName($naturalOrdering =false) | ||
| { | ||
| $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
nicolas-grekas commentedApr 24, 2018 • 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.
New features should target master (aka 4.2)! |
vyshkant commentedApr 24, 2018
@nicolas-grekas So I have to add a message to |
nicolas-grekas commentedApr 24, 2018
yes please |
| publicfunctionsortByName(/* bool $useNaturalSort = false */) | ||
| { | ||
| $this->sort =Iterator\SortableIterator::SORT_BY_NAME; | ||
| $useNaturalSort =1 ===func_num_args() &&true ===func_get_arg(0); |
nicolas-grekasApr 24, 2018 • 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.
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)
vyshkant commentedApr 24, 2018
Does anybody have any idea why AppVeyor build has been failed? |
nicolas-grekas 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.
(failure unrelated)
fabpot commentedMay 30, 2018
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#9671Added `$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
Uh oh!
There was an error while loading.Please reload this page.
Added
$useNaturalSortoptional argument toFinder::sortByName()method. If it is specified and equals totrue,"natural sort order" algorithm will be applied, which means thatstrnatcmpfunction will be used instead ofstrcmp(see#26930 for details).