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 and require 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 this
/**
* @template TDataType
*/
trait MyTrait {}
class MyClassA {}
class MyClassB {
/** @phpstan-use MyTrait<MyClassA> */
use MyTrait;
}
This 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 this
/**
* @template TDataType
*/
trait MyTrait {}
class MyClassA {}
/**
* @phpstan-use MyTrait<MyClassA>
*/
class MyClass {
use MyTrait;
}
Did 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.
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,
includeandrequirestatements (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.