// OK.
use Vendor\Package\ClassName as OtherClassName;
use function Vendor\Package\functionName as otherFunctionName;
use const Vendor\Package\CONSTANT_NAME as OTHER_CONSTANT_NAME;
// Not OK.
use Vendor\Package\ClassName as ClassName;
use function Vendor\Package\functionName as functionName;
use const Vendor\Package\CONSTANT_NAME as CONSTANT_NAME;
// Should also be checked for trait `use` statements
class Aliased_Talker {
use A {
A::bigTalk as talk; // OK
A::smallTalk as smallTalk; // Not OK.
}
}
Additional context (optional)
Aliasing to the same name, but in a different case should also be flagged, though maybe with a separate error code.
Namespace, OO and function names in PHP are case-insensitive, so aliasing to the same name in a different case is just as useless.
Note: constants are generally case-sensitive, except when explicitly declared as case-insensitive using define(). Probably still a good idea to flag that even so.
Is your feature request related to a problem?
It would be nice to have a sniff which would detect and flag when an alias is the same as the original name.
PHP will allow this just fine - https://3v4l.org/DIT7X#veol / https://3v4l.org/Gd4M7#veol - , but it is useless to do so.
Describe the solution you'd like
A new sniff to detect useless aliases.
Additional context (optional)
Aliasing to the same name, but in a different case should also be flagged, though maybe with a separate error code.
Namespace, OO and function names in PHP are case-insensitive, so aliasing to the same name in a different case is just as useless.
Note: constants are generally case-sensitive, except when explicitly declared as case-insensitive using
define()
. Probably still a good idea to flag that even so.