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
Allow @phpstan-use
(and @use
) in PHPdoc-block for classes
#7486
Comments
This is fairly easy to do. Places that read |
Your comment sounds a little like you would like me to implement it. But I do not feel qualified at all. I can write a simple additional inspection rule using your guide, but as soon as it involves interaction with different components of PHPStan, I am lost. |
Do not feel obligated - it's a hint for everyone that feels like doing this :) |
Why have you closed this issue? |
Sorry, that was by mistake. |
Ondrey likes to close issues faster that the speed of light. |
any progress on this, i was trying to doctype my trait wondering why it wouldnt work as i thought it would be in the class block |
This will also break with generics inheritance: https://phpstan.org/r/953e9ea0-604f-4ce7-b64f-b3a9352b9845 The message reported will be |
I had the same wish today, so I implemented it. |
I have also bumped into this problem in Drupal, where DrupalCS (via PHPCS) does not allow docblock comments above trait use statement.
|
@ondrejmirtes It seems to me that #2638 implements a different approach than what you have described in #7486 (comment). Would you also accept the solution in #2638 or rather a new PR should be raised that would implemented your suggested approach? |
Feature request
PHPStan only recognizes annotations, if the annotation is inside a PHPdoc block (see PHPStan: PHPDocs Basics). But PHPdoc blocks are only allowed for structural elements of the PHP language as well as files,
include
andrequire
statements (see phpDocumentor: What can be documented in your source code?).However, if one uses a generic trait with a template parameter, one has to annotate the
use
-statement with the proper template parameter like thisThis is not 100% ideal as there are other tools (e.g. CS Fixer for PHP) which convert those wrongly placed PHPdoc comments into normal comments.
A solution would be to put this annotation into the PHPdoc block of the class (similar to
@extends
) like thisDid PHPStan help you today?
Currently, we are enabling PHPStan for Lychee as part of this PR LycheeOrg/Lychee#1336. While we are struggling with a lot of false positives due to the used framework, it already helped us to discover a lot of bugs which were dormant in less frequently used features of Lychee.
The text was updated successfully, but these errors were encountered: