Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add generic support to @method definitions #160

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

Merged
ondrejmirtes merged 7 commits into phpstan:1.9.x from tyabu12:method-tag-generics
Dec 7, 2022

Conversation

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

@ondrejmirtes ondrejmirtes Nov 1, 2022

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

@ondrejmirtes ondrejmirtes Nov 1, 2022

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

@ondrejmirtes ondrejmirtes Nov 1, 2022

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.

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

@ondrejmirtes ondrejmirtes Nov 1, 2022

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

@tyabu12 tyabu12 Nov 1, 2022

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.

Copy link
Member

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

tyabu12 reacted with heart emoji

@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
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
Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /