Skip to content

Commit

Permalink
AlphabeticallySortedUsesSniff: fixable supports functions and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Jan 4, 2018
1 parent a788a1a commit df7bed1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ private function fixAlphabeticalOrder(

$phpcsFile->fixer->addContent($firstUseStatement->getPointer(), implode($phpcsFile->eolChar, array_map(function (UseStatement $useStatement): string {
$unqualifiedName = NamespaceHelper::getUnqualifiedNameFromFullyQualifiedName($useStatement->getFullyQualifiedTypeName());

$useTypeName = $useStatement->getTypeName();
$useTypeFormatted = $useTypeName !== null ? sprintf('%s ', $useTypeName) : '';

if ($unqualifiedName === $useStatement->getNameAsReferencedInFile()) {
return sprintf('use %s;', $useStatement->getFullyQualifiedTypeName());
return sprintf('use %s%s;', $useTypeFormatted, $useStatement->getFullyQualifiedTypeName());
}

return sprintf('use %s as %s;', $useStatement->getFullyQualifiedTypeName(), $useStatement->getNameAsReferencedInFile());
return sprintf('use %s%s as %s;', $useTypeFormatted, $useStatement->getFullyQualifiedTypeName(), $useStatement->getNameAsReferencedInFile());
}, $useStatements)));
$phpcsFile->fixer->endChangeset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
use P\Q\R\T;
use U\V\W\Z;
use U\V\X\Y;
use const PHP_OS;
use const X\BOO;
use const X\FOO;
use function strpos;
use function X\boo;
use function X\foo;

class Alphabetical
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace Abc;

use function X\foo;
use const X\FOO;
use \A;
use \H\I\K;
use \H\I\J;
use const PHP_OS;
use \B\C as Ccc;
use L\M\O;
use const X\BOO;
use L\m\O as Ooo;
use function strpos;
use D\E\F;
use \U\V\X\Y;
use function X\boo;
use P\Q\R\T;
use \U\V\W\Z;
use P\Q\R\S;
Expand Down

0 comments on commit df7bed1

Please sign in to comment.