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

ExportedNodeResolver - Add support for attributes #1427

Conversation

olsavmic
Copy link
Contributor

@olsavmic olsavmic commented Jun 15, 2022

@olsavmic olsavmic force-pushed the olsavmic-exported-node-resolver-support-attributes branch from 865dc9f to 10637e0 Compare June 15, 2022 16:57
@olsavmic olsavmic force-pushed the olsavmic-exported-node-resolver-support-attributes branch from 33aa3f0 to e9da297 Compare June 15, 2022 17:16
@olsavmic
Copy link
Contributor Author

@ondrejmirtes Could you give me a hint on how to test this properly? I don't see any test cases related to ExportedNode* or DependencyResolver in the codebase.

Thank you!

public function __construct(
private ?string $name,
private string $value,
private bool $byRef,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Most likely not even possible, test it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the name here, being indexed correctly by int|string in ExportedAttributeNode should be fine.

Copy link
Contributor Author

@olsavmic olsavmic Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, you can switch named argument and keep the value & index.

Ok :)

Copy link
Contributor Author

@olsavmic olsavmic Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the src/Dependency/ExportedNode/ExportedAttributeArgumentNode.php entirely as it was storing only the expression value. Let me know if you prefer to keep it

public function __construct(
private ?string $name,
private string $value,
private bool $byRef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the name here, being indexed correctly by int|string in ExportedAttributeNode should be fine.

{

/**
* @param ExportedAttributeArgumentNode[] $args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array<int|string, ExportedAttributeArgumentNode> please

src/Dependency/ExportedNode/ExportedAttributeNode.php Outdated Show resolved Hide resolved
foreach ($attributeGroup->attrs as $attribute) {
$args = [];
foreach ($attribute->args as $arg) {
$args[] = new ExportedAttributeArgumentNode(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the argument should be indexed by $i or $arg–>name.

@ondrejmirtes
Copy link
Member

This is mostly fine :) As for testing - I'd say that static analysis mostly covers that because it's just about passing the correct values into the correct parameters. There's a ResultCacheEndToEndTest that tests a real-world project with result cache but it certainly doesn't use attributes because it's an old one.

So please just do the small modifications I asked for in the review, and it's ready to merge :) Thanks.

@olsavmic olsavmic force-pushed the olsavmic-exported-node-resolver-support-attributes branch from 8ed8cbc to 7ffe60e Compare June 17, 2022 12:35
@olsavmic olsavmic marked this pull request as ready for review June 17, 2022 12:35
@ondrejmirtes ondrejmirtes merged commit 1c2d5e6 into phpstan:1.7.x Jun 17, 2022
@ondrejmirtes
Copy link
Member

Thank you!

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