usegroup.sortfixable
Ensure usegroups are sorted
This rules sort usegroups. It first sorts top level by group type (class, const, function) then alphabetically by group name. It also sorts the items within each group alphabetically by item name.
Examples
- Examples of correct code for this rule using default options
Sorted use groups
php
<?php
namespace Taqwim\Test\Namespace;
use BadMethodCallException;
use Closure;
use Exception;
use Illuminate\Contracts\Database\{
Eloquent\Builder as BuilderContract,
Query\Expression
};
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\{
Concerns\BuildsQueries,
Query\Builder as QueryBuilder,
RecordsNotFoundException
};
use Illuminate\Database\Eloquent\{
Concerns\QueriesRelationships,
Relations\BelongsToMany,
Relations\Relation
};
use Illuminate\Pagination\Paginator;
use Illuminate\Support\{
Arr,
Str,
Traits\ForwardsCalls
};
use KalimahApps\Daleel\{
CodeHighlighter\CodeHighlighterExtension,
Config,
Containers\ContainerExtension,
ImagePathExtension,
InternalLinkExtension,
ViewBuilder
};
use Mailgun\Mailer as MailgunMailer;
use ReflectionClass;
use ReflectionMethod;
use Single\Traits\Test;
use SMTP\Mailer as SMTPMailer;
use Throwable;
use const Another\Vendor\CONSTANT_D;
use const League\CommonMark\Util\{
HTML,
JSON,
Xml
};
use const Vendor\Package\{
CONSTANT_A,
CONSTANT_B,
CONSTANT_C
};
use function Another\Vendor\functionD;
use function League\CommonMark\Util\{
HTML,
JSON,
Xml
};
use function Vendor\Package\{
functionA,
functionB,
functionC
};
Sorted use groups
php
<?php
use some\namespace\{
ClassA,
ClassB,
ClassC as C
};
use some\namespace\ClassA;
use some\namespace\ClassB;
use some\namespace\ClassC as C;
use const some\namespace\{
ConstA,
ConstB,
ConstC
};
use const some\namespace\ConstA;
use const some\namespace\ConstB;
use const some\namespace\ConstC;
use function some\namespace\{
fn_a,
fn_b,
fn_c
};
use function some\namespace\fn_a;
use function some\namespace\fn_b;
use function some\namespace\fn_c;
- Examples of incorrect code for this rule using default options
Unsorted use groups
php
<?php
namespace Taqwim\Test\Namespace;
use BadMethodCallException;
use Closure;
use SMTP\Mailer as SMTPMailer;
use Mailgun\Mailer as MailgunMailer;
use Illuminate\Contracts\Database\{
Eloquent\Builder as BuilderContract,
Query\Expression
};
use Illuminate\Contracts\Support\Arrayable;
use Exception;
use Illuminate\Database\Eloquent\{
Concerns\QueriesRelationships,
Relations\BelongsToMany,
Relations\Relation
};
use Illuminate\Pagination\Paginator;
use ReflectionClass;
use Illuminate\Support\{
Arr,
Str,
Traits\ForwardsCalls
};
use KalimahApps\Daleel\{
Config,
Containers\ContainerExtension,
ViewBuilder,
ImagePathExtension,
InternalLinkExtension,
CodeHighlighter\CodeHighlighterExtension
};
use Throwable;
use Illuminate\Database\{
Concerns\BuildsQueries,
Query\Builder as QueryBuilder,
RecordsNotFoundException
};
use ReflectionMethod;
use Single\Traits\Test;
use const League\CommonMark\Util\{
Xml,
JSON,
HTML
};
use const Vendor\Package\{
CONSTANT_B,
CONSTANT_C,
CONSTANT_A
};
use const Another\Vendor\CONSTANT_D;
use function League\CommonMark\Util\{
Xml,
JSON,
HTML
};
use function Vendor\Package\{
functionA,
functionB,
functionC
};
use function Another\Vendor\functionD;