You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
The use:sort command appears to have a bug where a class that has no imports but uses a trait from the same namespace it will treat the trait usage as if it was a file level import. This is causing issues in our builds which will fail the code on bad smell.
The replication is pretty simple. Have one class and a trait in the same namespace, make the class use the trait without import (as you should). In the examples below I added a method also to demonstrate that it also messes with the formatting of methods.
<?phpnamespaceSomeNamespace;
class MyClass
{
use MyTrait;
publicfunctionsomething()
{
return1;
}
}
Now run the command above on the src directory and the output will look something like this:
<?phpnamespaceSomeNamespace;
class MyClass
{
use MyTrait;
publicfunctionsomething()
{
return1;
}
}
Now obviously the temporary fix for this is to import the trait. Unless you are using an auto code formatter in which it will remove the useless import and then you are back where you started. Have you come across this issue? Personally I have never written a trait in the same directory as something implementing it one of my co-workers has and now this problem falls on me.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The
use:sort
command appears to have a bug where a class that has no imports but uses a trait from the same namespace it will treat the trait usage as if it was a file level import. This is causing issues in our builds which will fail the code on bad smell.The replication is pretty simple. Have one class and a trait in the same namespace, make the class use the trait without import (as you should). In the examples below I added a method also to demonstrate that it also messes with the formatting of methods.
The command:
File structure:
The class:
Now run the command above on the
src
directory and the output will look something like this:Now obviously the temporary fix for this is to import the trait. Unless you are using an auto code formatter in which it will remove the useless import and then you are back where you started. Have you come across this issue? Personally I have never written a trait in the same directory as something implementing it one of my co-workers has and now this problem falls on me.
The text was updated successfully, but these errors were encountered: