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

Sniff to detect useless alias names #233

Closed
jrfnl opened this issue Jun 13, 2023 · 1 comment · Fixed by #244
Closed

Sniff to detect useless alias names #233

jrfnl opened this issue Jun 13, 2023 · 1 comment · Fixed by #244

Comments

@jrfnl
Copy link
Member

jrfnl commented Jun 13, 2023

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.

// 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.

@jrfnl
Copy link
Member Author

jrfnl commented Jun 18, 2023

Note: PR #244 does not address useless aliases for trait use statements yet. This can be addressed at a later point in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant