-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[RFC] Import types with use
statements only for non native types
#2166
Comments
i remember there were request to do the other way around |
👎 for it from me, hard to implement when you want to remove import only for PHP-defined global classes and not user-defined global classes and have it working for all different PHPs, also, it makes execution slower... if one want to have it he could keep it without fixer I would say, if one want to automatically do the importing (Eg only before creating release) the fixer would be nice. but yeah, let us wait for more comments. |
Looks doable with little pain, but we might have to be careful when it comes to updating phpdoc. |
The phpdoc side of things maybe doesn;t make this worth the effort. |
I was just thinking about it, and wanted to open a ticket, then I ended up here. I like it! |
This PR was squashed before being merged into the 2.16-dev branch (closes #4355). Discussion ---------- GlobalNamespaceImportFixer - Introduction * closes #1309 * refs #2166 (this pr does not differientiate between native/non-native elements, only between global/non-global) * closes #2739 * closes #4347 --- The fixer can import global classes/functions/constants: Input: ```php <?php namespace Foo; if (\count($x)) { /** @var \DateTimeImmutable $d */ $d = new \DateTimeImmutable(); $p = \M_PI; } ``` Output: ```php <?php namespace Foo; use DateTimeImmutable; use function count; use const M_PI; if (count($x)) { /** @var DateTimeImmutable $d */ $d = new DateTimeImmutable(); $p = M_PI; } ``` Global functions/constants without leading `\` are not imported. The slash can be added by `Native(Constant|Function)InvocationFixer` before. The fixer can also do the reverse fix, adding the backslash to imported global classes/functions/constants. But the fixer does not remove the imports, this can be done by `NoUnusedImportsFixer`. Commits ------- 41fe1f4 GlobalNamespaceImportFixer - Introduction
#4355 is merged, should we close here? |
Yeah, looks good to me. Feel free to comment if I missed a detail in the discussion. Thanks again @gharlan for writing the fixer! |
This proposed fixer should perform the following transformation:
ACTUAL:
EXPECTED:
The text was updated successfully, but these errors were encountered: