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 support for event/job static dispatch calls on class itself #15

Open
JonasPardon opened this issue Jan 10, 2023 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@JonasPardon
Copy link
Owner

JonasPardon commented Jan 10, 2023

Events

https://laravel.com/docs/9.x/events#dispatching-events

  • EventClass::dispatch(...)
  • EventClass::dispatchIf(...)
  • EventClass::dispatchUnless(...)

Jobs

https://laravel.com/docs/9.x/queues#dispatching-jobs

  • JobClass::dispatch(...)
  • JobClass::dispatchIf(...)
  • JobClass::dispatchUnless(...)
  • JobClass::dispatchAfterResponse(...)
  • JobClass::dispatchSync(...)
@JonasPardon JonasPardon added the enhancement New feature or request label Jan 10, 2023
@ukkok
Copy link
Contributor

ukkok commented Mar 18, 2024

I was looking into this and AFAIK this requires some changes to static call detection logic.

As these classes are now hardcoded into method, we would need get all imported classes and try to check if there is used these predefined methods?

@JonasPardon
Copy link
Owner Author

I was looking into this and AFAIK this requires some changes to static call detection logic.

As these classes are now hardcoded into method, we would need get all imported classes and try to check if there is used these predefined methods?

Sorry, I'm a bit confused by your sentence. You mean we would need to:

  • Get all imported classes of the class we're currently checking
  • Then check each of those imported classes separately for usages of one of the dispatch methods?

Or am I understanding it wrong?

@ukkok
Copy link
Contributor

ukkok commented Mar 19, 2024

Maybe I should try to clarify my output, but what I meant was:

  • As we now have these classes hardcoded in methods getDispatchedEvents and getDispatchedJobs this code tries to find usage of these classes & methods inside subscribers and related classes.
  • To find jobs and events using this ClassName::dispatchsyntax, we need to have list of imported classes iterated through and then check have these defined methods been used

This is how far I have got with this reasoning. The problem here (I think) is that both event and jobs have dispatch method, which makes separating jobs and events a bit challenging.

@JonasPardon
Copy link
Owner Author

JonasPardon commented Mar 19, 2024

Alright I think I understand the issue.

A possible solution might be checking the dispatched class to see if they have a handle method, in which case they would be a Job, otherwise an Event. This however doesn't cover the case where a codebase has custom classes (that are not events or jobs) that have a static dispatch method, so they would be recognised as an Event.

Not sure if there's a more foolproof way though…

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

No branches or pull requests

2 participants