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

Ruleset::explain(): use natural sorting #3868

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function __construct(Config $config)
public function explain()
{
$sniffs = array_keys($this->sniffCodes);
sort($sniffs);
sort($sniffs, (SORT_NATURAL | SORT_FLAG_CASE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Would using natcasesort() be more legible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll need to check if that function was available in PHP 5.4.

Copy link
Contributor Author

@jrfnl jrfnl Aug 14, 2023

Choose a reason for hiding this comment

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

Just checked, yes, the function is available, but is still not the right choice.

natcasesort() maintains key association. sort() does not.
The foreach() loop used in the function uses the (numeric) key to determine whether the end of the array has been reached, so the array not being re-indexed could cause it to stop the loop too early or even to display sniffs with the wrong standard.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, I'd forgotten about that inconsistency. Thanks for checking / remembering!


ob_start();

Expand Down