As mentioned in PR #75 it is better to use use in header. Then you only need to change that header and not all references in many lines.
A very tiny example:
````
use \Vendor\Project\Type\Foo;
$fooInstance = new Foo();
[...]
$someValue = Foo::getSomeValueFromBar($bar);
```
Now just imagine the world withoutuse, you have to update many lines. Withuse`, you only need to touch the header of the file, nothing more.
I agree. Do you know a tool that could do that ?
Hmm, it might be possible to automatically change this, or include it in PHP-CS.
There is a sniff that checks all referenced names are imported via the use in the Slevomat Coding Standard (SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly) but there is no automatic fix for it. I guess it is because there is no way to automatically handle the case when there are two classes with the same name in different namespaces.
Yes, that is true. Okay, so only manually doing this is possible.
So this will change a lot files. How should I proceed to make this lesser painful [to reviewers]? For each "package" (namespace) a separate PR? Or per folder a separate PR (to keep them small)?
@Quix0r I just examined the sniff I posted and I think I can make it auto-fixable for non-conflicting cases during this or next weekend if you are willing to wait :-)
@jankonas sure, will wait here.
Sorry for the delay, I don't have the time to do this right now. But Slevomat released v2.0 of their coding standard which now has the SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly sniff auto-fixable. So I suggest using it and keeping it in the project so it checks usage of uses in the future. Of course, many of the other sniffs have to be excluded to pass the checks.
Most helpful comment
I agree. Do you know a tool that could do that ?