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

Review how docblock class imports are handled #2358

Open
dingo-d opened this issue Aug 18, 2023 · 1 comment
Open

Review how docblock class imports are handled #2358

dingo-d opened this issue Aug 18, 2023 · 1 comment

Comments

@dingo-d
Copy link
Member

dingo-d commented Aug 18, 2023

I noticed that in the docblocks we are unsing FQCN when adding types to the parameters. We are also importing those at the top of the file.

In most of the editors, the editor is smart enough that it will know to what class/interface we are referring to.

So we should consider maybe shortening the FQCNs in the docblocks?

Example:

<?php
...

namespace WordPressCS\WordPress\Helpers;

use PHP_CodeSniffer\Files\File;
...
// Later in the class/trait/interface:
	/**
	 * ...
	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.

Could be written as:

<?php
...

namespace WordPressCS\WordPress\Helpers;

use PHP_CodeSniffer\Files\File;
...
// Later in the class/trait/interface:
	/**
	 * ...
	 * @param File $phpcsFile The file being scanned.

As the File is imported at the top of the file.

Thoughts?

@jrfnl
Copy link
Member

jrfnl commented Aug 18, 2023

I tend to favour FQNs in docblocks for two reasons:

  1. Docblocks are not subject to use statements, so while most IDEs are smart enough by now, not everyone uses an IDE and we cannot expect them to.
  2. Docblocks may be re-used outside the context of the code - think a documentation website generated with phpDocumentor or other tooling. In that case, it can be hit-or-miss whether the names will be resolved correctly.

Using FQNs in docblocks prevents issues in both cases.

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

No branches or pull requests

2 participants