-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add generic support to @method
definitions
#160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please fix the build failures :)
use PHPStan\PhpDocParser\Ast\NodeAttributes; | ||
use PHPStan\PhpDocParser\Ast\Type\TypeNode; | ||
|
||
class MethodTagValueGenericNode implements Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this doesn't need a new node, but TemplateTagValueNode can be reused instead. We'd also gain default template types (#148) automatically :)
@@ -20,17 +20,21 @@ class MethodTagValueNode implements PhpDocTagValueNode | |||
/** @var string */ | |||
public $methodName; | |||
|
|||
/** @var MethodTagValueGenericNode[] */ | |||
public $generics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This thing should be called $templateTypes
probably.
/** @var MethodTagValueParameterNode[] */ | ||
public $parameters; | ||
|
||
/** @var string (may be empty) */ | ||
public $description; | ||
|
||
public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description) | ||
public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $generics, array $parameters, string $description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter needs to be added as last and needs to be optional, otherwise it's a BC break.
@ondrejmirtes |
src/Parser/PhpDocParser.php
Outdated
$templateTypes = []; | ||
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) { | ||
do { | ||
$templateTypes[] = $this->parseMethodTagValueTemplateType($tokens); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we call the already existing parseTemplateTagValue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes
I fixed it.
parseTemplateTagValue
also parse description
text, so it was necessary to add the flag parameter $parseDescription
.
This is perfect, thank you very much :) I hope you follow-up with an implementation in phpstan-src :) |
I see that this was added in phpdoc-parser over a year ago, but you never followed up with implementing this in phpstan-src. Can you please do? Thanks. |
This allows implementing phpstan/phpstan#6371 to add support
@method
generics.