Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
May 30, 2018
Merged

[Finder] added "use natural sort" option #27024

merged 1 commit into from
May 30, 2018

Conversation

vyshkant
Copy link
Contributor

@vyshkant vyshkant commented Apr 23, 2018

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 will be applied, which means that strnatcmp function will be used instead of strcmp (see #26930 for details).

Copy link
Member

@nicolas-grekas nicolas-grekas left a 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)
Copy link
Member

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 */)

Copy link
Member

@javiereguiluz javiereguiluz Apr 24, 2018

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

nicolas-grekas commented Apr 24, 2018

New features should target master (aka 4.2)!

@vyshkant
Copy link
Contributor Author

New features should target master (aka 4.2)!

@nicolas-grekas So I have to add a message to CHANGELOG.md under 4.2.0 section (not under 4.1.0)?

@nicolas-grekas
Copy link
Member

add a message to CHANGELOG.md under 4.2.0 section

yes please

@vyshkant vyshkant changed the base branch from 3.4 to master April 24, 2018 11:55
@vyshkant vyshkant changed the title [Finder] added "natural ordering" sort option [Finder] added "natural sort" option Apr 24, 2018
@vyshkant vyshkant changed the title [Finder] added "natural sort" option [Finder] added "use natural sort" option Apr 24, 2018
{
$this->sort = Iterator\SortableIterator::SORT_BY_NAME;
$useNaturalSort = 1 === func_num_args() && true === func_get_arg(0);
Copy link
Member

@nicolas-grekas nicolas-grekas Apr 24, 2018

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
Copy link
Contributor Author

Does anybody have any idea why AppVeyor build has been failed?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(failure unrelated)

@fabpot
Copy link
Member

fabpot commented May 30, 2018

Thank you @vyshkant.

@fabpot fabpot merged commit e697c7d into symfony:master May 30, 2018
fabpot added a commit that referenced this pull request May 30, 2018
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
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
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