Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Workflow] Add generic template for event classes #44622

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

Closed
wants to merge 1 commit into from
Closed

[Workflow] Add generic template for event classes #44622

wants to merge 1 commit into from

Conversation

fractalzombie
Copy link
Contributor

@fractalzombie fractalzombie commented Dec 14, 2021

Added generic template for Event in Workflow Component

Q A
Branch? 6.1
Bug fix? no
New feature? no
Deprecations? no
License MIT

Added generic template for Event, Event::$subject and Event::getSubject() for PHPStorm support.

@carsonbot carsonbot added this to the 6.1 milestone Dec 14, 2021
@fractalzombie fractalzombie changed the base branch from 6.1 to 5.4 December 14, 2021 16:02
@derrabus
Copy link
Member

Can you elaborate your motivation for this change? Why do you need these annotations?

@derrabus
Copy link
Member

Also, please target the 6.1 branch.

@fractalzombie
Copy link
Contributor Author

Can you elaborate your motivation for this change? Why do you need these annotations?

For PHPStorm generic support.

@derrabus
Copy link
Member

The Psalm error looks related.

@derrabus
Copy link
Member

Can you elaborate your motivation for this change? Why do you need these annotations?

For PHPStorm generic support.

That's a very generic answer (no pun intended). Can you be more specific? How do the annotations help you? What would PhpStorm do differently if we added them to the codebase?

@derrabus derrabus changed the base branch from 5.4 to 6.1 December 14, 2021 17:43
@derrabus derrabus changed the title [Workflow] Added generic template for Event and his inheritors and … [Workflow] Add generic template for event classes Dec 14, 2021
@fractalzombie
Copy link
Contributor Author

Can you elaborate your motivation for this change? Why do you need these annotations?

For PHPStorm generic support.

That's a very generic answer (no pun intended). Can you be more specific? How do the annotations help you? What would PhpStorm do differently if we added them to the codebase?

What are you mean, when you say "What would PhpStorm do differently if we added them to the codebase?". I think it's not about what PHPStorm do differently, it's about, when we can Annotate Event with Event<EntityOrModel> and then we can have intellisense with Storm.

@derrabus
Copy link
Member

when we can Annotate Event with Event<EntityOrModel> and then we can have intellisense with Storm.

That kind-of answers my question, I guess.

Would it make sense to add the template type for the subject to the workflow object as well?

@fractalzombie
Copy link
Contributor Author

fractalzombie commented Dec 14, 2021

when we can Annotate Event with Event<EntityOrModel> and then we can have intellisense with Storm.

That kind-of answers my question, I guess.

Would it make sense to add the template type for the subject to the workflow object as well?

We can add, but in workflow it will be do nothing because it's only be available in library.

@@ -43,6 +48,9 @@ public function getMarking()
return $this->marking;
}

/**
* @return TSubject|object
Copy link
Member

Choose a reason for hiding this comment

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

This does not look correct. We should always get a TSubject here. Wasn't that the whole point of the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, in this case psalm have issue, says that it can be object or Tsubject

Copy link
Contributor

@ro0NL ro0NL Dec 15, 2021

Choose a reason for hiding this comment

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

What issue? https://psalm.dev/r/4582b1218d

if anything, adding |object creates an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove it now, and we see

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. Maybe try to reproduce on psalm.dev, but here psalm seems wrong AFAIK.

@stof
Copy link
Member

stof commented Dec 15, 2021

To make psalm happy, I think you need to add @var TSubject in the phpdoc of the property, so that psalm considers the property as being of type TSubject rather than object

@fractalzombie
Copy link
Contributor Author

To make psalm happy, I think you need to add @var TSubject in the phpdoc of the property, so that psalm considers the property as being of type TSubject rather than object

You can check upper, I already do this, but @derrabus don't happy with it.

@stof
Copy link
Member

stof commented Dec 15, 2021

Well, we need to annotate both the constructor and the property, because the property inference of psalm is done based on the native argument type rather than the phpdoc type (and in that case, we need the more precise type TSubject).

@fractalzombie
Copy link
Contributor Author

Well, we need to annotate both the constructor and the property, because the property inference of psalm is done based on the native argument type rather than the phpdoc type (and in that case, we need the more precise type TSubject).

Added, fixed.

@fractalzombie fractalzombie changed the base branch from 6.1 to 5.4 December 15, 2021 10:00
@fractalzombie
Copy link
Contributor Author

Well, we need to annotate both the constructor and the property, because the property inference of psalm is done based on the native argument type rather than the phpdoc type (and in that case, we need the more precise type TSubject).

I think the last commit is worked

@derrabus derrabus closed this Dec 15, 2021
@derrabus derrabus reopened this Dec 15, 2021
…for `Event::$subject` and `Event::getSubject()`
@derrabus derrabus changed the base branch from 5.4 to 6.1 December 17, 2021 18:05
@fractalzombie
Copy link
Contributor Author

@derrabus something strange is going on with my fork, i need to recreate, and we can close this and accept this #44702.

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

Successfully merging this pull request may close these issues.

5 participants