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

GlobalNamespaceImportFixer needs option to ignore types on doc blocks #4854

Open
hackel opened this issue Feb 27, 2020 · 0 comments
Open

GlobalNamespaceImportFixer needs option to ignore types on doc blocks #4854

hackel opened this issue Feb 27, 2020 · 0 comments

Comments

@hackel
Copy link

@hackel hackel commented Feb 27, 2020

Currently the GlobalNamespaceImportFixer tries to import classes from phpdoc annotations, even if they aren't actually used in the code. This is an issue when your coding style dictates that you always use FQCNs in doc blocks only. I don't want it to use the imported class name or import unnecessary classes.

Ideally, it would also have an option to rewrite it to use the FQCN, but that should probably be a separate rule. (functions y and z below)

  • before running PHP CS Fixer (no changes):
<?php
namespace Test;

use Exception;

/** @throws \Throwable */
function x() {}

/** @throws Throwable */
function y() {}

/** @throws Exception */
function z() {}
  • with the changes you expected instead:
<?php
namespace Test;

use Exception;

/** @throws \Throwable */
function x() {}

/** @throws \Test\Throwable */
function y() {}

/** @throws \Exception */
function z() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.