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

IDE Helpers Prototype #117

Closed
Wulfheart opened this issue May 25, 2021 · 15 comments · Fixed by lorisleiva/laravel-actions-docs#18
Closed

IDE Helpers Prototype #117

Wulfheart opened this issue May 25, 2021 · 15 comments · Fixed by lorisleiva/laravel-actions-docs#18

Comments

@Wulfheart
Copy link
Collaborator

Problem

Given the following action:

class SendTeamReportEmail
{
    use AsAction;

    public function handle(Team $team, bool $fullReport): void
    {
        // ...
    }
}

When I'm trying to e.g. dispatch a job via SendTeamReportEmail::dispatch() I don't get method signature.

image

Therefore I wrote a package which analyzes all actions in a project and creates an ide-helper file like https://github.com/barryvdh/laravel-ide-helper.

Installation

composer require --dev wulfheart/laravel-actions-ide-helper

Usage

php artisan ide-helper:actions

Result

image

Limitations

It is just a prototype. Therefore the package currently has some limitations.

Ignoring the decorator functions

class SendTeamReportEmail
{
    use AsAction;

    public function handle(Team $team, bool $fullReport): void
    {
        // Prepare report and send it to all $team->users.
    }

    public function asJob(Team $team): void
    {
        $this->handle($team, true);
    }
}

If I understand the inner workings of Laravel Actions correctly this action has now some other parameters applied if it is dispatched as Job. Currently it assumes the parameters of the handle function. I will have to fix this.

No default value

If a parameter has default value (e.g. bool $fullReport = true) the default value doesn't get recognized. This will get fixed later.

Opinion

@lorisleiva What is your opinion on this? Do you think this could be an addition to Laravel Actions or a separate package to improve the developer experience?

@Wulfheart
Copy link
Collaborator Author

Update:
The package now supports autocompletion for some decorator functions in an action.

image

Furthermore are the different decorators in an action recognized and the parameters of the accessor funtions like makeJob() are set properly.
Default types are working now.

@lorisleiva
Copy link
Owner

Hey Alex 👋

I really like this! I currently fix this for the run method manually by adding a @method docblock on the class itself that reflects the handle method parameters and return type.

Having something that generates it for me for all methods supported by Laravel Actions is really great!

I think it sit well as a third-party package though because we can't assume everyone is using PHPStorm but I will be using it for sure.

If you're up for it, maybe you could add a new page on the Laravel Actions documentation under the "Guide" section that acts as a little tutorial to install and use your package?

Thank you for your work on improving the LA ecosystem I truly appreciate it.

P.S.: I'll catch up with some of the other issues soon. I've been quite busy with freelance work lately but it's certainly on my To-Do list.

@Wulfheart
Copy link
Collaborator Author

Wulfheart commented May 30, 2021

I think it sit well as a third-party package though because we can't assume everyone is using PHPStorm but I will be using it for sure.

Packages like laravel-ide-helper also work with vscode.

If you're up for it, maybe you could add a new page on the Laravel Actions documentation under the "Guide" section that acts as a little tutorial to install and use your package?

Yes, will open a PR later.

Thank you for your work on improving the LA ecosystem I truly appreciate it.

Thank you for the kind words. I really like LA because it gives me flexibility.

@lorisleiva
Copy link
Owner

Packages like laravel-ide-helper also work with vscode.

Oh I did not know that. It's up to you really. I'm all up for adding wulfheart/laravel-actions-ide-helper to Laravel Actions' dependencies in order to make it easier for users to generate these IDE helpers.

@Wulfheart
Copy link
Collaborator Author

Ah, the minimum requirement is PHP 8, therefore I'm just going to reference it in the docs.

@lorisleiva
Copy link
Owner

Ah no worries. I'll probably drop support for 7.4 in a future release so I'll keep that in mind when I do. 🙂

@Wulfheart
Copy link
Collaborator Author

@lorisleiva Just published a new version. Even though I wrote tests for it it would be nice if you could take a look at it if you encounter any problems with it. Therefore, I am going to reopen this issue, but feel free to close it if it is out of your current scope.

@Wulfheart Wulfheart reopened this Feb 19, 2022
@lorisleiva
Copy link
Owner

Hey Alex, Thanks for that. I don't have time to fully test that at the moment (just started a new job haha) but you've been so helpful with this package I really trust your judgment. Feel free to open up a PR if you want Laravel Actions to ship with this IDE helper (if you think it should).

@eclipse313
Copy link

I think it would be a very good idea to extend Laravel Actions with IDE Helper. I can of course open a PR to add @Wulfheart's package as a dependency, however I think it might make sense to include the package's content directly in the core?

@Wulfheart
Copy link
Collaborator Author

Wulfheart commented Feb 14, 2023

@eclipse313 to be honest I don't really maintain the package anymore. But somehow this package has over 80k downloads. 😆 I would be really happy to see this package directly in this package but it is upon @lorisleiva to decide if he wants to have this additional maintenance burden.

@eclipse313
Copy link

Can we come back to this? Would it be an option for you @lorisleiva to integrate the code directly into the core? I think this could be very helpful, especially for people who are new to Laravel Actions.

@lorisleiva
Copy link
Owner

Hey @eclipse313, I agree this would be a nice addition but I'm afraid I don't have the bandwidth to work on this. If someone is up for working on a PR and maintaining this part of the codebase going forward, I'd be happy to review it and merge it in.

@Wulfheart
Copy link
Collaborator Author

Btw I would also be open to transfer maintainership for that package as I don’t use Actions anymore.

@nikuscs
Copy link

nikuscs commented May 16, 2024

Might be interested in continue the IDE-Helper package, in the meanwhile i have done a fork and bump stuff to latest + some bugfixes & suporting multiple-paths to search ( for Slices and Domain design approaches )

https://github.com/flavorly/laravel-actions-ide-helper

composer require --dev flavorly/laravel-actions-ide-helper

@Wulfheart
Copy link
Collaborator Author

Closing due to inactivity. If you feel your issue is still relevant please open a new one with a link to a repository containing a minimal reproducible example.

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 a pull request may close this issue.

4 participants