lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.41k stars 116 forks source link

IDE Helpers Prototype #117

Open Wulfheart opened 3 years ago

Wulfheart commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

lorisleiva commented 3 years ago

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 commented 2 years ago

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

lorisleiva commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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

nikuscs commented 2 months ago

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