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

Make global usage of use in header of files #78

Closed
Quix0r opened this issue Jan 23, 2017 · 7 comments
Closed

Make global usage of use in header of files #78

Quix0r opened this issue Jan 23, 2017 · 7 comments
Milestone

Comments

@Quix0r
Copy link
Contributor

Quix0r commented Jan 23, 2017

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 without use, you have to update many lines. With use, you only need to touch the header of the file, nothing more.

@PowerKiKi
Copy link
Member

I agree. Do you know a tool that could do that ?

@PowerKiKi PowerKiKi added this to the 1.0 milestone Jan 23, 2017
@Quix0r
Copy link
Contributor Author

Quix0r commented Jan 23, 2017

Hmm, it might be possible to automatically change this, or include it in PHP-CS.

@jankonas
Copy link

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.

@Quix0r
Copy link
Contributor Author

Quix0r commented Feb 23, 2017

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)?

@jankonas
Copy link

@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 :-)

@Quix0r
Copy link
Contributor Author

Quix0r commented Feb 23, 2017

@jankonas sure, will wait here.

@jankonas
Copy link

jankonas commented Mar 17, 2017

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.

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

No branches or pull requests

3 participants