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

Add generic support to @method definitions #160

Merged
merged 7 commits into from
Dec 7, 2022

Conversation

tyabu12
Copy link
Contributor

@tyabu12 tyabu12 commented Nov 1, 2022

This allows implementing phpstan/phpstan#6371 to add support@method generics.

Copy link
Member

@ondrejmirtes ondrejmirtes left a 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
Copy link
Member

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;
Copy link
Member

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)
Copy link
Member

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.

@tyabu12
Copy link
Contributor Author

tyabu12 commented Nov 1, 2022

@ondrejmirtes
Thank you for quick reviewing!
I fixed your review comments and build failures.

$templateTypes = [];
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
do {
$templateTypes[] = $this->parseMethodTagValueTemplateType($tokens);
Copy link
Member

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?

Copy link
Contributor Author

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.

@tyabu12 tyabu12 requested a review from ondrejmirtes November 3, 2022 03:34
@ondrejmirtes
Copy link
Member

This is perfect, thank you very much :) I hope you follow-up with an implementation in phpstan-src :)

@ondrejmirtes ondrejmirtes merged commit 2a4686e into phpstan:1.9.x Dec 7, 2022
@tyabu12 tyabu12 deleted the method-tag-generics branch December 8, 2022 14:22
@ondrejmirtes
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

2 participants