Page MenuHomePhabricator

MediaWiki.Classes.UnsortedUseStatements.UnsortedUse does not handle 'use function'
Open, Needs TriagePublicBUG REPORT

Description

Here is a sample phpcbf output:

 use GuzzleHttp\Client;
-use function GuzzleHttp\default_user_agent;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
 use Psr\Log\NullLogger;
 use UtfNormal\Validator;
 use Wikimate;
+use function GuzzleHttp\default_user_agent;

I don't think this makes sense. use clauses for the same component should be grouped together whether they are about classes or fuctions.
(Or maybe functions should be in another, newline-separated section, but than that's what the fix should do.)

Event Timeline

UnsortedUseStatementsSniff has explicit code to sort classes, then functions, then constants - @thiemowmde implemented that in rMCSN119736cda846: Full rewrite of the UnsortedUseStatementsSniff

The sniff was checking the order for the 3 groups "classes", "functions", and "constants" independent from each other. Something like use A; use function C; use B; was considered ok because "A → B" are in the correct order, and "C" is in the correct order as well.

The new code sorts alphabetically within each group, and then orders the groups, with a comment

// Preferred order is classes → functions → constants

@thiemowmde could you elaborate on why you chose to have the three groups one after another, instead of mixed together and sorted only by the names?

Sure.

  • Mixing classes, functions and constants was never intended by this sniff, neither before nor after I rewrote that part. In other words, it was not me making this decision.
  • This is how IDEs like PHPStorm auto-sort that as well.

The error message should be clearer then - a message saying "not alphabetically sorted" gives the user little idea how the code should be fixed.